Search code examples
gitgit-mergebranching-and-merging

How to get changes from another branch limiting by date on git


I have a Branch called "hugefeature" which was forked from "master" on January.

People worked all the year on this "hugefeature" branch, and also on "master".

But since July, all the changes made on this branch are not important. In fact, this changes breaks the previous work. Software were working fine before July and after that it's not working anymore.

So what I want to is:

  • Fork "master" again and create a "hugefeature2" new branch.
  • Merge "hugefeature" into "hugefeature2", but getting only changes made on "hugefeature" before July.

It'll be some conflicts since "master" has changes. But that's ok, I can solve that.

Can someone please help? I don't know how to do it limiting by the commit date.


Solution

  • git log has a --until=<date>, --before=<date> option, which you can use to spot the commit ID you are interested in :

    git log --oneline --graph --until=2020-07-01 hugefeature
    

    One you have spotted the commit id you are interested in, you can use it to either create a new branch :

    git checkout -b hugefeature2 <commitID>
    

    or use this ID directly in a merge command :

    # fork from master :
    git checkout -b hugefeature2 master
    # merge commits up to july :
    git merge <commitID>