tags:

views:

52

answers:

2

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

+3  A: 

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

Roman Cheplyaka
A: 

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

jonescb
No, it does not erase data. It just moves your branch pointer. The previous commit still exists, and you can see its ID by looking at `git reflog` (f.ex.). It will get garbage-collected in two months (default configuration), but you can turn off automatic garbage collection, and then *every single commit* you *ever* made will exist forever in that repository. They just aren't reachable via branches. But you can always find them using `git fsck`, and I’ve posted a recipe for browsing all commits that uses that.
Aristotle Pagaltzis