开发者

Syncing two GIT branches that only differ by a couple of files

I have a couple of branches defined for the current proj开发者_如何学Cect where all but the master branch differ from master only by the same small set of files (less than ten).

After implementing a new feature in master I would like to replicate those changes and additions to the other branches with the least effort. What's the recommended approach here?


You have three choices:

  • merge: interesting if all changes of master need to be visible in one branch, but that is not always the case

  • cherry-pick: to only apply certain commit to a branch

  • rebase: the best solution if your branch has not yet been pushed: you replay the commit of your branch on top of master

But: in the three cases, you need to checkout the branch where you want to integrate the changes, and repeat that for each branches.

Unless your branches are made from one to another:

---o             branch B1
    \
     ----o       branch B2
          \
           ----o branch B3

In that case, you could:

  • only merge the changes to the most specific branch (B3 here), as recommanded in this FAQ
  • finish your work on B3
  • then merge on the parent branch B2 (if no evolutions took place on B2, this is actually a fast-forward merge)
  • repeat for B1 (that is: finish your work on B2, git checkout B1, git merge B2)


Normally when I fix some important thing on one branch(may even be master), and if I want the same fix to be replicated to another branch, I do git checkout my_latest_feature and git merge --no-commit master

Never tried cherry-pick, but I think, thats the best way I guess, as cherry-pick will only merge that specific change and git merge --no-commit master will try to get the whole tree(even other commits besides the latest fix).

I always hate any command which tampers commit history. Thats the reason why I never rebase

Update: just found this similar question: How to copy commits from one branch to another?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜