Undoing commits
Last updated
Last updated
▪ git reset --hard and --soft
▪ git revert
Reset performs different actions depending on the arguments:
With a path
Without a path
By default, git performs git reset --mixed
.
git checkout
will move the HEAD but the branch stays where it was. git reset
will move the HEAD and the branch reference, meaning the branch is now modified.
For commits: moves the HEAD pointer, and optionally modifies files. For file paths: does not move HEAD pointer, modifies files.
There are three options for git reset
:
1️⃣ GIT RESET --soft
▪ moves HEAD
git reset --soft HEAD~
now HEAD points to the previous commit (because ^
indicates parent of the current commit).
Before:
After:
2️⃣ GIT RESET --mixed (the default)
▪ move HEAD, copy files to stage
Before:
After:
3️⃣ GIT RESET --hard
▪ move HEAD, copy files to stage & working! (destructive operation because you lose files untracked in the working area)
Before:
After:
git reset --hard
cleans staging and working trees.