用git同时提交多个分支 [英] Commit to multiple branches at the same time with git

查看:1038
本文介绍了用git同时提交多个分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个我正在开发的项目中有两个分支A和B. B与A的区别在于一次提交,它是代码的一部分,完全独立于我正在为下一次工作(也就是说,我将推出许多提交到分支A和B的提交)。



git中有什么办法可以同时提交给分支A和分支B,而不必将其提交给一个分支,检出另一个分支,并且尝试樱桃选择提交(S)。

解决方案

您可以:




  • A
  • 上进行所有提交
  • rebase B 位于 A 之上(如果您还没有推送B,那就是)



这样, B 将包含所有来自 A 的提交,加上它的单个提交。






如果您共享了 B 远程回购),这个想法更多的是将任何对 A 进行的提交添加到 B (也就是顶部 B )。

最简单的方法是在 B A >,如果你不介意在 B 上只有一个提交,表示所有来自 A 的提交。

我更希望任何涉及cherry-picking的解决方案对于在 B 上重新创建的每个提交都会有不同的SHA1,这将使任何未来的合并重新回到 A 复杂(因为Git会返回找到共同祖先的很长的路)


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).

解决方案

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)

这篇关于用git同时提交多个分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆