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

发布于 2024-09-18 02:08:12 字数 40 浏览 3 评论 0原文

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寻梦旅人 2024-09-25 02:08:12

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

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

活雷疯 2024-09-25 02:08:12

命令 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 run git revert HEAD again 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.

HEAD~ means the commit before the current HEAD

且行且努力 2024-09-25 02:08:12

怎样才能恢复原状呢?

查看 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

烟柳画桥 2024-09-25 02:08:12

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

$ 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)

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

$ 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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文