(Based on Justin Hileman’s Flowchart)

Starting Point
"So you have a mess on your hands"
1. Uncommitted Mess
-
Caught in time?
-
Yes → Split into logical chunks, stage, and commit with a good message.
-
Still messy? →
git reset --hard
-
2. Accidental Commit
-
Has anyone else seen it?
-
No (local only):
-
Last commit:
-
Forgot a file? →
git add <file> git commit --amend -
Need a better message? →
git commit --amend -
Want to discard it? →
git reset --hard HEAD^
-
-
Older commit:
-
Reset to a specific commit →
git reset <commit> -
Interactive rebase →
git rebase -i <commit>
-
-
-
Yes (pushed to GitHub / shared):
-
Is anyone downstream?
-
Yes → Safest to leave history ugly.
-
No → Inform collaborators → Interactive rebase + force push:
git rebase -i <commit> git push --force origin <branch>
-
-
-
3. History Cleanup
-
Remove merge commits?
- If yes → Interactive rebase works.
-
Need to change commit history?
-
Reset and recommit from scratch →
git reset <commit> -
Interactive rebase (DangerZone™):
git rebase -i <commit> git push --force origin <branch>
-
4. Golden Rules
- If commits are shared: Don’t rewrite history unless absolutely necessary.
- If local only: Feel free to reset, amend, or rebase.
- Always communicate with collaborators before force pushing.
Common Commands Summary
- Discard uncommitted mess:
git reset --hard - Fix last commit:
git commit --amend - Discard last commit:
git reset --hard HEAD^ - Reset to specific commit:
git reset <commit> - Interactive history edit:
git rebase -i <commit> - Rewrite & publish history:
git push --force origin <branch>