Commit to multiple branches at the same time with git

别说谁变了你拦得住时间么 提交于 2019-11-30 22:55:44

问题


I have two branches A and B in a project that I am working on. B differs from A by a single commit, which is a section of the code completely independent from what I'm working on for the next while (aka, I will have many commits I want to push to both branch A and B).

Is there any way in git that I can commit to both branch A and branch B at the same time, without having to commit it to one branch, checkout the other, and try to cherry pick out the commit(s).


回答1:


You could:

  • make all your commits on A
  • rebase B on top of A (if you haven't pushed B already, that is)

That way, B will include all commits from A, plus its single commit.


If you have shared B (pushed to a common remote repo), the idea is more to add any commit made on A to B (that is, "on top of B).

The simplest way would be to merge A on B, if you don't mind having only one commit on B representing all commits from A.
I would prefer that to any solution involving cherry-picking would mean different SHA1 for each commit recreated on B, which would make any future merge back to A complicated (because Git would go back a long way to find a common ancestor)




回答2:


the cherry-pick feature is a better way to do this, check answer at

Git: Commit to multiple branches at the same time



来源:https://stackoverflow.com/questions/4532063/commit-to-multiple-branches-at-the-same-time-with-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!