简体   繁体   English

Git - 父分支丢弃了一些提交,如何将提交同步到子分支

[英]Git - Parent branch had dropped some commits, how to sync the commits into child branch

提交图像

just like the image show above, in branch1(Br1) had done drop the commit C, but branch2(Br2) still keep it, how to sync the commits log into branch2 when I need to merge Br2 into Br1就像上面的图片一样,在 branch1(Br1) 中已经删除了提交 C,但是 branch2(Br2) 仍然保留它,当我需要将 Br2 合并到 Br1 时如何将提交日志同步到 branch2

You need to rebase br2 to get rid of the old branch if br1 was rewritten to get rid of C .如果br1被重写以摆脱C ,则需要重新设置br2以摆脱分支。 Assuming that both branches are local (and if they are remote adjust the instructions to use them):假设两个分支都是本地的(如果它们是远程的,请调整使用它们的说明):

git rebase old-commit-for-E br2 --onto new-commit-for-E-or-br1

old-commit-for-E is the old commit of E as you have it in br2 . old-commit-for-EE的旧提交,就像您在br2中一样。 Then if you feel like placing the branch on top of br1 , use it as the parameter of --onto ... otherwise, get the new commit id for E and use it there.然后,如果您想将分支放在br1之上,请将其用作--onto的参数...否则,获取E提交 id 并在那里使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM