Git : Undo commits, Viewing Unpushed Git Commits


[1] First note that there is a difference between ‘revert’ and ‘reset’


[2]  Undoing a ‘git add’ before doing a ‘git commit’

Note:  For this scenario, most of the above links are recommending doing a ‘git reset’. There is a difference between a ‘soft’ reset and a ‘hard’ reset.


[3] Recently I had to undo a commit I had made into my local git repo. I was under the impression that reverting commits in Git is a big hassle. To my surprise, it didn’t prove to be too much of a pain. These are things I had to do basically:

  • couple of git reset --soft HEAD~ commands (because there was stuff I had pulled into my repo after commiting)
  • couple of   git checkout —  <file> commands to undo my inadvertent changes.

That was it!  I got my repo back to sanity.


[4]  Another import task is to view unpushed git commits. this is an important thing to do, especially before making commits into a remote branch.