遇到问题" git revert"合并我的分支后

时间:2015-09-29 23:08:00

标签: git github

我有三个分支:master,A和B.

分支" A"和" B"应该彼此独立。在拉取请求之后,master从A和B更新了。现在,我不小心将B合并到A中。

我立即通过git revert -m

恢复了此合并

但是现在当我把B拉成主人时,在A中恢复合并会破坏分支B的变化。这是因为分支A已经"恢复合并B"提交。

我如何删除"还原合并分支B"和"合并分支B"承诺? 我尝试使用git -rebase命令,但它没有帮助我,git创建了不在pull请求中的anthoer分支。

1 个答案:

答案 0 :(得分:5)

简单回答: git docs

恢复还原,因为

  

所以,如果你想到"还原" as"撤消",然后你就会永远   想念这部分还原。是的,它撤消了数据,但不,它没有   撤消历史记录。

添加更多内容:

不幸的是,您在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.

解决git revert问题的一些链接:

  1. Undo a git merge (hasn't been pushed yet)

  2. git revert, reset and merge problems