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
Git Revert a Revert for a Merge
提问by Serendipity
I had a feature branch created, let's say feature/branch1
on github.
I created a pull request for it and got it merged.
我创建了一个功能分支,比方说feature/branch1
在 github 上。我为它创建了一个拉取请求并将其合并。
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.
当它到达我们的管道时,我们认为存在问题,我们使用 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_commit
PR 分支重置 ( ) 到您要还原到的提交(已还原的提交) - 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 log
on 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。