收录日期:2020/12/05 23:18:17 时间:2010-09-07 20:40:12 标签:git,undo,revert

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

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

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

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