The git reset command is a powerful Git tool used to undo changes by moving the HEAD pointer. It can unstage files, remove commits, or discard changes entirely depending on the mode used.
// General syntax for git reset
git reset <option> <commit-hash>
// Undo last commit but keep changes staged
git reset --soft HEAD~1
// Unstage changes but keep them in working directory
git reset --mixed HEAD~1
// Completely discard last commit and all local changes
git reset --hard HEAD~1
After running a reset command, Git updates the HEAD pointer. Depending on the mode, your staging area and working directory may also be updated or cleared.
Visualize HEAD moving backward on the commit graph while files either stay staged, unstaged, or deleted based on reset mode.
git status before reset