GtGit · Lesson 6 of 8
Undoing Things
The whole point of git is that mistakes are recoverable. Here's the undo toolbox — from 'fix my last commit message' to 'where did my work go?'
⚠ Warning
Rules of thumb: use revert on commits that were already pushed (it doesn't rewrite history). Use reset only on commits that exist just on your machine. And --hard deletes uncommitted work with no confirmation — check git status first.
Rules of thumb: use revert on commits that were already pushed (it doesn't rewrite history). Use reset only on commits that exist just on your machine. And --hard deletes uncommitted work with no confirmation — check git status first.
✦ Tip
Almost nothing committed is ever truly lost — reflog keeps entries for ~90 days. If you're mid-panic: stop running commands, run git reflog, breathe, then reset to the entry from before things went wrong.
Almost nothing committed is ever truly lost — reflog keeps entries for ~90 days. If you're mid-panic: stop running commands, run git reflog, breathe, then reset to the entry from before things went wrong.