Git Quick Ref
Git Quick Reference¶
The commands that cover 95% of this course.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
The panic table¶
| Situation | Command | Danger |
|---|---|---|
| Wrong file edited, not staged | git restore <file> |
loses that edit |
| Staged by mistake | git restore --staged <file> |
safe |
| Bad message (not pushed) | git commit --amend -m "..." |
safe if unpushed |
Committed to main by mistake |
git switch -c rescue, then reset main |
safe |
| Committed build output | git rm -r --cached <dir> + .gitignore |
safe |
| Merge conflict | edit markers → git add → git commit |
safe |
| Want out of a merge | git merge --abort |
safe |
| Undo a pushed commit | git revert <hash> |
safe — prefer this |
| “I lost commits” | git reflog |
safe |
One rule above all: if the work is committed anywhere, it’s recoverable. git reflog
will find it. The only work Git can’t save is work you never committed — which is the real
argument for committing often.