git log
Appendix C — Undoing commits
This is a beta version.
C.1 Undoing a local commit
- Check commit history:
or
git log --pretty=oneline
This shows both the commit history of our current branch, with the latest commit at the top. It also shows the head of our local directory and the head of our remote repository.
- If this was just the previous commit, we can reset the last commit by doing
git reset HEAD~1
The files on disk will not be touched and any changes will between the original HEAD and the commit we reset will be kept. The files will be unstaged.
- If we need to go back to a commit that’s buried in the commit history, it’s best to use the hash of the commit.
git reset <hash>
C.2 References
GitHub Blog - How to undo (almost) anything with Git
David Zych - Difference between git reset soft, mixed and hard