有什么办法可以消除“git revert head”的影响?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3662543/
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-10 09:03:48  来源:igfitidea点击:

Is there any way to undo the effects of "git revert head"?

gitundorevert

提问by blueberryfields

I've accidentally run the command against the wrong branch in my repository - is there a way to undo this change?

我不小心对存储库中的错误分支运行了命令 - 有没有办法撤消此更改?

回答by Roman Cheplyaka

git revertjust creates a new commit -- you can "remove" it with git reset --hard HEAD^(be more careful with it, though!)

git revert只需创建一个新的提交——你可以“删除”它git reset --hard HEAD^(不过要小心!)

回答by jonescb

The command git revertjust creates a commit that undoes another. You should be able to run git revert HEADagain and it'll undo your previous undo and add another commit for that. Or you could do git reset --hard HEAD~. But be careful with that last one as it erases data.

该命令git revert只是创建一个撤销另一个提交。您应该能够git revert HEAD再次运行,它会撤消您之前的撤消并为此添加另一个提交。或者你可以这样做git reset --hard HEAD~。但是要小心最后一个,因为它会擦除数据。

HEAD~means the commit before the current HEAD

HEAD~表示当前HEAD之前的提交

回答by Lasma

How about reverting the revert?

还原还原怎么样?

View git log and get the hash tag of the bad revert:

查看git log,获取bad revert的hash标签:

git log -5

git log -5

Then do reverse the revert itself:

然后反转还原本身:

git revert

git revert

回答by ericP

If you were prescient enough to have done this: revert --no-commit master, you can abort that with: git revert --abortper the git statusadvice:

如果您有足够的先见之明这样做:revert --no-commit master,您可以git revert --abort根据git status建议中止:

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
You are currently reverting commit dcc7c46.
  (all conflicts fixed: run "git revert --continue")
  (use "git revert --abort" to cancel the revert operation)