Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

undo

revert

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

like image 983
blueberryfields Avatar asked Sep 07 '10 20:09

blueberryfields


People also ask

Does git revert remove changes?

The git revert command looks a lot like the reset command, and is also used to undo your changes in a project. We saw earlier how reset just wipes off data in your Git's state, and these commits are completely removed from the Commit History.

How do I undo a committed head?

First git reset --hard HEAD^ You've now blown away all local changes from the last commit. Then: git push --force origin HEAD This takes the current HEAD commit in local and overwrites the HEAD in the remote, removing the last commit.


2 Answers

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

like image 102
Roman Cheplyaka Avatar answered Oct 12 '22 22:10

Roman Cheplyaka


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

like image 42
jonescb Avatar answered Oct 12 '22 23:10

jonescb