gitmergebranchcherry-pick

Merge all commits from a branch to another


At some point in our project we started a new development environment in which, in order to run properly, we were forced to make many changes in our code. Those changes are in a branch named "dev-test" that was created from "master".

This environment (that started as a test) is actually becoming our development environment, so when a new feature has to be done, our flux would be:

Well, this last step is actually the problem. How could we get the changes from "feat1" without getting the changes from "dev-test"?

A small graphic to clarify:

                 f1---f2             feat1
                 /      \       
      d1--(dn)--d2--d3--d4--(...)    dev
     /     
m1--m2--m3--m4--m5--m6--m7           master

What we want would be to add commits "f1" and "f2" to branch "master" (after "m7"). If we just merge "feat1" to "master" we will have all "dn" commits on master (what we don't want). We can always cherry-pick "f1" and "f2" from "feat1" to "master" but I'm afraid that in more complex cases we can miss some commits or messed up with merges.

There are any good solutions for this problem? Something like "merge all commits from A branch to B branch"?


Solution

  • You need to rebase on top of master (as a new branch, say)... something like:

    git branch blah feat1
    git rebase dev-test blah --onto master
    

    Now the branch with the changes from feat1 only can be merged into master.