I have run into a bit of a problem here: I had a problem-specific branch 28s in Git, that I merged in the general develop branch. Turns out I had done it too fast, so I used git-revert to undo the merge. Now, however, the time has come to merge 28s into develop, but git-merge command sees the original merge, and happily announces that all is well and branches have been already merged. What do I do now? Create a 'Revert "Revert "28s -> develop"" ' commit? Doesn't seem to be a good way to do it, but I can't imagine any other at the moment.
树的结构是什么样子的:
你可以在devel分支中使用这个命令来丢弃(撤销)错误的合并提交(而不是仅仅恢复它),而不是使用git-revert。
git checkout devel
git reset --hard COMMIT_BEFORE_WRONG_MERGE
这也将相应地调整工作目录的内容。小心:
将您的更改保存在开发分支中(因为错误的合并),因为它们
Too将被git-reset删除。所有提交都在您指定的之后
git重置参数将消失!
另外,如果您的更改已经从其他存储库中取出,则不要这样做
因为重置将改写历史。
我建议在尝试之前仔细研究git-reset手册页。
现在,重置后,你可以在devel重新应用你的更改,然后做
git checkout devel
git merge 28s
这将是一个真正的合并从28s到devel像最初的一个(现在是
从git的历史中删除)。
你必须“还原还原”。取决于你是如何还原原始文件的,它可能不像听起来那么容易。看看关于这个话题的官方文件。
---o---o---o---M---x---x---W---x---Y
/
---A---B-------------------C---D
允许:
---o---o---o---M---x---x-------x-------*
/ /
---A---B-------------------C---D
But does it all work? Sure it does. You can revert a merge, and from a
purely technical angle, git did it very naturally and had no real
troubles.
It just considered it a change from "state before merge" to
"state after merge", and that was it.
Nothing complicated, nothing odd,
nothing really dangerous. Git will do it without even thinking about it.
So from a technical angle, there's nothing wrong with reverting a merge,
but from a workflow angle it's something that you generally should try to
avoid.
If at all possible, for example, if you find a problem that got merged
into the main tree, rather than revert the merge, try really hard to:
bisect the problem down into the branch you merged, and just fix it,
or try to revert the individual commit that caused it.
Yes, it's more complex, and no, it's not always going to work (sometimes
the answer is: "oops, I really shouldn't have merged it, because it wasn't
ready yet, and I really need to undo all of the merge"). So then you
really should revert the merge, but when you want to re-do the merge, you
now need to do it by reverting the revert.