Git – Undoing things

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

  • 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:

http://stackoverflow.com/questions/2003505/delete-a-git-branch-both-locally-and-remotely

Rename a local and remote branch:

http://stackoverflow.com/questions/1526794/rename-master-branch-for-both-local-and-remote-git-repositories

http://lrotherfield.com/blog/delete-remote-git-repo-to-specific-commit/

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}