March 9, 2015

Git – Undoing things

There are 3 common things you may want to undo when using git:


You can find all my latest posts on medium.
  • undo a commit
  • unstage a file
  • unmodify a file

If you have done several commits and you want to roll back several commits, then do:

git log -p

This will list commit id’s pick the id you want to roll back to, then do:

git reset --hard e0e7671b58895cfa1bbca4016238c693efaa4fbe

This will rollback to a commit with the id above. Be careful with this command, because you cannot undo this.

If you wan to delete a remote branch:

Rename a local and remote branch:

if you have unstaged changes of a folder and it’s contents, and you want to undo all the changes you made in that folder then do:

git checkout -- {folder-name}