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
-
-
Save hardyoyo/deca73f4337d380f43d0aa3a7a5a9387 to your computer and use it in GitHub Desktop.
Process notes: I pasted the original image into ChatGPT and asked for a Mermaid.js formatted version of the chart. It obliged, and after I corrected 3 syntax errors and one huge omission, this was the result.
GitHub can do a lot more than just Mermaid diagrams, you should check it out if you'd like to play around: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-diagrams
Oh... I used mermaid-cli to convert this to a PDF:
mmdc -i git-pretty.md -o git-pretty.pdf -f
I'll see if I can attach it here. Nope, GitHub won't let me add a PDF as a comment.
The chart has been implemented as a cli app: https://github.com/draperunner/git-pretty
Also, if you’re in the market for git help: https://github.com/VirtusLab/git-machete
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.
A copy of the original diagram lives on in this Reddit post.