简体   繁体   English

哪个提交哈希使用git-revert撤消推送合并?

[英]Which commit hash to undo a pushed merge using git-revert?

I merged the beta branch into the master branch. 我将beta分支合并到主分支中。 I pushed to origin. 我推到原点。 I now want master to be as it was prior to the merger both locally and remotely. 我现在希望master在本地和远程合并之前就像它一样。

A good answer for undoing a merge that was already pushed suggests 撤消已经推送的合并的一个很好的答案表明

git revert -m 1 commit_hash

If this is indeed the way to go, how can I determine commit_hash ? 如果这确实是要走的路,我该如何确定commit_hash I unsuccessfully tried the hash returned by merge-base : 我没有成功尝试merge-base返回的哈希:

$ git merge-base --all master beta
1f4b949b7ef97abf913ae672e3acd0907abfac1b
$ git revert -m 1 1f4b949b7ef97abf913ae672e3acd0907abfac1b
error: Mainline was specified but commit 1f4b949b7ef97abf913ae672e3acd0907abfac1b is not a merge.
fatal: revert failed

I've examined both git-log and gitk renditions of the branches, but they're very long, and I am uncertain enough of my interpretation to feel I should seek assistance before making a perhaps bigger mess. 我已经检查了分支的git-log和gitk再现,但是它们很长,我不太清楚我的解释,觉得我应该寻求帮助才能做出更大的混乱。 Beta was derived from v2 which was derived from master. Beta来自v2,它来自master。 There have been some mergers from master into v2 and beta along the way as I've kept the new branches up-to-date with master. 随着我与主人保持最新的分支机构,我们已经有一些从大师到v2和beta的合并。 The merger in the direction from beta into master was a mistake I wish to correct. 从beta到Master的方向的合并是我想纠正的错误。

Once I do determine the merge point, if I find any commits made on master after the merger that really should be on the beta branch, what's the best way to move them over? 一旦我确定了合并点,如果我发现在合并之后对master进行的任何提交真的应该在beta分支上,那么移动它们的最佳方法是什么?

You need to find the commit of the merge, git merge-base tells you the commit where you can do the merge. 你需要找到合并的提交, git merge-base告诉你提交你可以在哪里进行合并。 It basically is the last commit that exists in those two branches. 它基本上是这两个分支中存在的最后一个提交。 The merge commit exists in your master branch only, unless you created a new branch after the merge, but that's not relevant here. 合并提交仅存在于主分支中,除非您在合并后创建了新分支,但这与此处无关。 :) :)

To find the merge commit try: git log master ^beta --ancestry-path --merges 要找到合并提交,请尝试: git log master ^beta --ancestry-path --merges

The needed commit is the very last commit. 所需的提交是最后一次提交。

But please read up on Linus' write up: http://www.kernel.org/pub/software/scm/git/docs/howto/revert-a-faulty-merge.txt 但请阅读Linus的文章: http//www.kernel.org/pub/software/scm/git/docs/howto/revert-a-faulty-merge.txt

Also look at http://sethrobertson.github.com/GitFixUm/ which walks you through almost any git problem, including pushed merges. 另请参阅http://sethrobertson.github.com/GitFixUm/ ,它将引导您解决几乎任何git问题,包括推送合并。 However...pushed merges have no easy solution. 然而......推动合并没有简单的解决方案。

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

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