假设我有两个分支A
和B
(A)--------(A+B)--------------(A+B+R)
\ / merge \ revert /
\ / \ /
(B)----(B+) (R)----
首先,我将分支B
合并到A
,
然后我用GitHub的恢复功能恢复了合并请求。
现在,当我在分支B
上修复某些代码并需要再次合并到A
时,几乎所有更改(除了我修复的新代码)都会被忽略。我怎样才能再次获得更改?
答案 0 :(得分:1)
您需要还原还原,即还原先前还原创建的提交。
这样做的原因是合并确实做了两件事:它改变了文件内容以反映合并,并且还创建了一个包含2个父项的提交来告诉git合并了什么。当你恢复时,它会撤消第一件事,但不是第二件事。因此,当您尝试重新执行合并时,git不知道您还原了之前的合并,因此在此之前它会忽略所有内容。
答案 1 :(得分:1)
在这里阅读如何"重置"你的改变 How to move HEAD back to a previous location? (Detached head)
获得所需的代码后,再将其推送到存储库。由于您进行了还原而未重置,因此您只需简单地推送代码即可。
如果您已完成reset
并希望更新远程分支,则必须force
推送git push -f origin master
,这将导致一个影响所有同事也是如此。
我怎样才能再次获得更改?
git cherry-pick
最简单的方法就是让git cherry-pick
再次选择所需的提交回到您的分支。
# Find out the range of commits you wish to re-add to your branch.
# then use cherry-pick to add them back to the branch
git cherry-pick start..end
# If you wish to include the start commit as well add the ^
# This will result in a cherry-pick of the start commit included as well
git cherry-pick start^..end
git rebase --onto
(Carefull = rebase)# reset it to the start commit
git reset --hard start
# rebase every commit after b and transplant it onto a
git rebase --onto commit1 commit2 commit3 ... commitN