Monday, September 3, 2018

How to undo a Git commit that was not pushed

Whoops... I just commited my work while not noticing I was on the master.

From here, there are 3 options to undo that commit.

1. Undo commit and completely remove all changes

git reset --hard HEAD~;

2. Undo commit and unstage all files
git reset HEAD~;

or

git reset --mixed HEAD~;


3.  Undo commit and keep all files staged
git reset --soft HEAD~;