Skip to content

Instantly share code, notes, and snippets.

@briancarycom
Created April 30, 2020 00:35
Show Gist options
  • Save briancarycom/62964bbcb08b5865a5674d6f206d47eb to your computer and use it in GitHub Desktop.
Save briancarycom/62964bbcb08b5865a5674d6f206d47eb to your computer and use it in GitHub Desktop.
[Undo git commit] Soft and hard delete git commits #git
https://stackoverflow.com/questions/927358/how-do-i-undo-the-most-recent-local-commits-in-git
How to undo a local commit
git reset --soft HEAD^ # Use --soft if you want to keep your changes
git reset --hard HEAD^ # Use --hard if you don't care about keeping the changes you made
How to undo a public commit
git revert HEAD
Your changes will now be reverted and ready for you to commit:
git commit -m 'restoring the file I removed by accident'
git log
commit 102: restoring the file I removed by accident
commit 101: removing a file we don't need
commit 100: adding a file that we need
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment