有什么方法可以消除“git revert head”的影响吗?
我不小心对存储库中的错误分支运行了命令 - 有没有办法撤消此更改?
I've accidentally run the command against the wrong branch in my repository - is there a way to undo this change?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
git revert
只是创建一个新的提交——你可以使用git reset --hard HEAD^
来“删除”它(不过要小心一点!)git revert
just creates a new commit -- you can "remove" it withgit reset --hard HEAD^
(be more careful with it, though!)命令 git revert 只是创建一个撤消另一个的提交。您应该能够再次运行 git revert HEAD ,它将撤消您之前的撤消操作并为此添加另一个提交。或者你可以执行
git reset --hard HEAD~
。但要小心最后一个,因为它会删除数据。HEAD~
表示当前 HEAD 之前的提交The command
git revert
just creates a commit that undoes another. You should be able to rungit revert HEAD
again and it'll undo your previous undo and add another commit for that. Or you could dogit reset --hard HEAD~
. But be careful with that last one as it erases data.HEAD~
means the commit before the current HEAD怎样才能恢复原状呢?
查看 git log 并获取错误恢复的哈希标签:
git log -5
然后反转恢复本身:
git revert
How about reverting the revert?
View git log and get the hash tag of the bad revert:
git log -5
Then do reverse the revert itself:
git revert
如果您足够有先见之明,可以这样做:
revert --no-commit master
,您可以根据git status使用:
建议:git revert --abort
来中止该操作If you were prescient enough to have done this:
revert --no-commit master
, you can abort that with:git revert --abort
per thegit status
advice: