graph TD;
A[So you have a mess on your hands] -->|Yep| B[What sort of mess?]
B -->|An uncommitted mess| C[Do you care enough about your mess to keep it?]
C -->|Yes| D[Looks like we caught this just in time]
D --> E[Split off a logical chunk from your mess, stage it, & commit it with a good message.]
E -->|Still have a mess?| F[No, we're cool now]
F --> G[Everything is going to be fine]
E -->|Yes| H[git reset --hard]
H --> G
C -->|No| I[git reset --hard]
I --> G
B -->|I accidentally committed something| J[My Git history is ugly]
J -->|Has anyone else seen it?| K[No]
K -->|Not yet| L[Is it already on GitHub?]
L -->|No| M[How long ago?]
M -->|Last commit| N[What would make this better?]
N -->|I forgot to add a file| O[git add myfile]
O --> P[git commit --amend]
P --> G
N -->|A better message| Q[git commit --amend]
Q --> G
N -->|Just throw the last commit away| R[git reset --hard HEAD^]
R --> G
M -->|It seems like forever ago| S[Should we remove merge commits?]
S -->|That would do the trick| T[git rebase origin/branch]
T --> G
S -->|No, I need to change history| U[Take a mulligan?]
U -->|Yes| V[We'll reset and commit from scratch]
V --> W[git reset COMMITISH]
W --> G
U -->|No| X[Is anyone downstream?]
X -->|Yes| Y[Enough to form a lynch mob?]
Y -->|Yes| Z[It's safest to let it stay ugly then]
Y -->|No| AA[Do you hate them?]
AA -->|Yes| Z
AA -->|No| AB[Send them a note, let 'em know you're changing history.]
AB --> AC[We're going to do an interactive rebase!]
AC --> AD[DangerZone™, you should git switch -c temporary-branch just to be safe]
AD --> AE[git rebase -i COMMITISH]
AE --> AF[...]
AF --> AG[git push --force origin branch]
AG --> G
X -->|No| AC
J -->|Yes| AH[git revert COMMITISH]
AH --> AI[(I do not think it means what you think it means.)]
AH --> G
Created
March 7, 2025 19:00
-
-
Save hardyoyo/deca73f4337d380f43d0aa3a7a5a9387 to your computer and use it in GitHub Desktop.
A version of Justin Hileman's Git Pretty diagram in Mermaid.js syntax, for easy refactoring.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For the record, the git-pretty diagram originally appeared on this (now gone) blog post: https://justinhileman.info/article/changing-history With the Internet Archive's Wayback Machine pretty much under permanent attack, there may be no way to recover the original diagram. I have reached out to Justin Hileman for his permission to create a derivative work. If he agrees, I'll move this gist to a new GitHub repository.