How to undo a Git rollback

11,182

Solution 1

If you are ok with command line, go to you repo, do a git reflog and get the commit which you want to "rollback" to and do a git reset --hard <commit>

You would also be able to do git reset --hard HEAD@{1} and then come back to egit and rollback to the desired commit.

Solution 2

I find that generally it's better to make your changes forward in time rather than backward.

Git's approach is to "revert" the commit. When you revert a commit, you check out into your working directory the inverse of the commit in question. Then you add and commit that, and you've just made a NEW commit, that commits the "undoing" of the commit you're reverting, AND it leaves a record in history that such a thing happened, so if you want to undo your undoing, it's easy to do.

Share:
11,182
Chironex
Author by

Chironex

Updated on June 04, 2022

Comments

  • Chironex
    Chironex almost 2 years

    I wanted to rollback to the last commit after making a massive error, but I managed to rollback a little too fair. The commit I wanted to reassert doesn't appear when I enter 'git log' in bash (I suppose because it's no longer in the history). Is there any way I can recover the last commit by date?

    I'm also using eGit in eclipse for the same project if that makes things easier. Thanks.

  • Dan Ray
    Dan Ray almost 13 years
  • Phil Miller
    Phil Miller almost 13 years
    When you recognize that you've done something erroneous before it's an indelible part of history (i.e. been shared with others), it's preferable to not record it. Recording bad commits means that tools like git bisect have more to stumble over.
  • Dan Ray
    Dan Ray almost 13 years
    I guess that's true. I find that clear commit messages save me from too much grief in that regard. And if I need to revert my revert (which from time to time I have), it's good to have it there to revert.