To undo git commit or reset or revert you can use this command below:
git reset HEAD~
Sometime people ask to me how to revert a Git repository? How to undo the last commit? or how to cancel a local git commit? Then how do I delete un-pushed git commits? that ‘blue‘ is the answer. But if you want to removing multiple commits from the top, you can run git reset HEAD~5 too.
How To Undo, Reset, Revert Commits In Git
When your situation is get accidentally committed wrong files to Git, but you haven’t pushed the commit to the server yet. My suggestion for undo changes in git is using a number after “~”, that’s mean to remove the last x commits. But if you have a nice trick for undoing or removing commits in Git, please comment down below guys.
- Do not use git reset –hard because this is a completely unrecoverable operation, any changes which are removed here cannot be restored later. This will not delete untracked or ignored files.
- Keep using best practice to reset changes in git if you don’t want to lose all the changes.
- That is the simple git tutorial about how to undo, reset, revert commits in Git.
This is more reference to learn how to undo a previous source in Git: