How to undo anything in Git: reset vs revert, recovering lost commits with reflog, undoing pushes and amending safely.
▶ Full written tutorial (free): https://generalistprogrammer.com/tuto...
You committed to the wrong branch, force-pushed over a teammate, or ran
git reset --hard and watched hours of work vanish. Take a breath: almost
nothing in git is ever really gone. Every commit is a full snapshot, and every
time HEAD moves — commit, reset, rebase, checkout, merge — git records it in a
private log called the reflog. So even a commit no branch points to is still in
your repository, and the reflog is your map back to it.
This video walks through every undo scenario, worst case first:
Nothing is ever lost: git's model (commits are snapshots; the reflog tracks
every HEAD move — local only, ~90 day expiry).
git reflog, the safety net: how to read HEAD@{n} entries and recover with
git reset --hard HEAD@{n} or git checkout -b recover SHA.
Undo your last commit, 3 ways: git reset --soft HEAD~1 (keep changes STAGED),
git reset HEAD~1 / --mixed (keep changes UNSTAGED), git reset --hard HEAD~1
(DISCARD changes — still reflog-recoverable). Wrong message only? git commit
--amend.
Reset vs revert: reset moves the branch pointer and rewrites history (safe
only locally); revert adds a NEW inverse commit and preserves history (safe
when pushed/shared). The rule: revert public history, reset local history.
Undo a push: on a shared branch use git revert SHA then push; on a solo
branch, git reset --hard GOOD-SHA then git push --force-with-lease (never
plain --force — force-with-lease refuses if someone else pushed).
Recover a deleted branch: git reflog for the tip SHA, then
git branch NAME SHA (deleting only drops the pointer; commits survive).
The panic flowchart: committed? pushed? shared? → the exact command to run.
Free written guide — how to undo a git commit:
https://generalistprogrammer.com/tuto...
Also see git reset vs revert:
https://generalistprogrammer.com/tuto...
Want to go further? Git & GitHub Mastery Pack, 15 dollars, optional:
https://generalistprogrammer.gumroad....
— Chapters —
0:00 Nothing is ever lost
1:05 git reflog — the safety net
2:40 Undo the last commit — 3 ways
4:06 Reset vs Revert
5:26 Undo a push
6:47 Recover a deleted branch
8:04 The panic flowchart
9:16 Recap + next step
#git #github #gitreflog