Git Revert a Revert for a Merge

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43221775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:42:13  来源:igfitidea点击:

Git Revert a Revert for a Merge

gitgithubmergegit-revert

提问by Serendipity

I had a feature branch created, let's say feature/branch1on github. I created a pull request for it and got it merged. Initial PR Merge Commit

我创建了一个功能分支,比方说feature/branch1在 github 上。我为它创建了一个拉取请求并将其合并。 初始 PR 合并提交

When it reached our pipeline, we figured there was a problem and we got it reverted using the Revert button on Git This created a "Revert" PR that we merged with the master and all was well. Reverted Merge Commit

当它到达我们的管道时,我们认为存在问题,我们使用 Git 上的“还原”按钮将其还原。这创建了一个“还原”PR,我们将其与主服务器合并,一切都很好。 恢复合并提交

After a few weeks, post other PRs that got merged into the master, we figured we would revert-the-revert. This time, we went into the Revert PR that was closed and tried to use the Revert button again. But we got this error message

几周后,发布合并到 master 中的其他 PR,我们认为我们将revert-the-revert。这一次,我们进入了关闭的 Revert PR 并尝试再次使用 Revert 按钮。但是我们收到了这个错误信息

Sorry, this pull request couldn't be reverted automatically. 
It may have already been reverted, or the content may have changed since it was merged.

How do I get this revert done?

如何完成此还原?

The most ideal situation I would like to have, is to have a new branch that contains the revert of the revert, so I can make further changes and go back through the PR process.

我想要的最理想的情况是有一个包含revert 的 revert的新分支,这样我就可以进行进一步的更改并返回 PR 过程。

回答by max630

The error which you see is artificial check of github, which I personally find unneeded. You can revert the revert locally then:

您看到的错误是对 github 的人工检查,我个人认为不需要。您可以在本地还原还原,然后:

git fetch origin master
git checkout origin/master (or reset)
git revert <REVERT HASH>
git push origin master

This should succeed, modulo conflicts with changes done since the revert.

这应该会成功,模与自恢复以来所做的更改发生冲突。

PS: actually, the error could be because of the conflicts.

PS:实际上,错误可能是因为冲突。

回答by VonC

What you can try is:

您可以尝试的是:

  • reset (git reset --hard old_commit) that PR branch to the commit you want to revert to (the one that was reverted)
  • force push (git push --force) that branch: that will update the PR
  • git reset --hard old_commitPR 分支重置 ( ) 到您要还原到的提交(已还原的提交)
  • force push( git push --force)那个分支:会更新PR

That way, the PR is done again with the old commit.

这样,PR 将再次使用旧提交完成。

This is a merge commit. The PR is already closed and merged.

这是一个合并提交。PR 已经关闭并合并。

In that case, if you have fetch that old PR branch, you can do:

在这种情况下,如果您获取了旧的 PR 分支,您可以执行以下操作:

  • a git logon it (git log origin/old_pr_branch)
  • a new branch from the old SHA1 commit representing the content you now want

    git checkout -b new_pr_branch old_sha1
    
  • a push to origin

    git push -u origin new_pr_branch

  • 一个git log关于它 ( git log origin/old_pr_branch)
  • 来自旧 SHA1 提交的新分支,代表您现在想要的内容

    git checkout -b new_pr_branch old_sha1
    
  • 推向原点

    git push -u origin new_pr_branch

You can then make a new PR from that new branch, with the right content.

然后,您可以从该新分支创建一个具有正确内容的新 PR。