5.4.2. git reset - How to step back and take a different turn?#
git reset moves the current HEAD to a specific state.
Diverging History
Setting back HEAD bares the risk to create an alternative history.
De-referenced Commits
Setting back HEAD bares the risk to leave commits without a reference (Tag or Branch). Such commits will be eventually deleted.
Example:
git reset HEAD~2:A ── B ── C ── D ── E (old tip, now orphaned)
^
└─ HEAD after `reset HEAD~2`
A ── B ── C ── F (new tip after the new commit)
git reset --softMoves HEAD back but keeps changes staged. Safest reset option.
git reset --mixedMoves HEAD back and unstages changes, but keeps them in working directory.
git reset --hard⚠️ DESTRUCTIVE: Moves HEAD back and deletes all changes. Use with extreme caution!