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

China☆狼群 提交于 2019-12-17 10:32:55

问题


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


回答1:


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




回答2:


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




回答3:


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




回答4:


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)


来源:https://stackoverflow.com/questions/3662543/is-there-any-way-to-undo-the-effects-of-git-revert-head

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!