我有三个分支:主,A和B.
分支"A"和"B"应彼此独立.在拉取请求之后,master从A和B更新了.现在,我不小心将B合并到了A中.
我立即通过这个合并恢复了这个合并 git revert -m
但是现在当我将B拉入master时,在A中恢复合并会破坏分支B的更改.这是因为分支A已经"恢复合并B"提交.
如何删除"还原合并分支B"和"合并分支B"提交?我试图使用git -rebase命令,但它没有帮助我,git创建了不在pull请求中的anthoer分支.
简单的回答: git docs
还原还原因为
因此,如果您将"恢复"视为"撤消",那么您将总是会错过这部分恢复.是的,它会撤消数据,但不会,它不会撤消历史记录.
添加更多内容:
不幸的是,你遇到了 git用户历史上最受欢迎的问题 :)
你的问题是一个错误的合并git merge branch B/branch A,你试图通过它来恢复它git revert
请记住,因此"恢复"会撤消数据更改,但它并非 "撤消",因为它不会撤消提交对存储库历史记录的影响.
我认为回答这个问题的更好的人就是linus torvalds,我找不到比他更好的人.
Reverting a regular commit just effectively undoes what that commit
did, and is fairly straightforward. But reverting a merge commit also
undoes the _data_ that the commit changed, but it does absolutely
nothing to the effects on _history_ that the merge had.
So the merge will still exist, and it will still be seen as joining
the two branches together, and future merges will see that merge as
the last shared state - and the revert that reverted the merge brought
in will not affect that at all.
So a "revert" undoes the data changes, but it's very much _not_ an
"undo" in the sense that it doesn't undo the effects of a commit on
the repository history.
So if you think of "revert" as "undo", then you're going to always
miss this part of reverts. Yes, it undoes the data, but no, it doesn't
undo history.
Run Code Online (Sandbox Code Playgroud)
一些解决git revert问题的链接: