
Here's a preview from my zine, How Git Works! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!

read the transcript!
commits in git are usually saved forever
But even if git still has your commits, they’re not always easy to find.
Some ways commits get “lost”:
git commit --amend
git rebase
- deleting an unmerged branch
git stash drop
the three levels of losing commits
- annoying: the commit isn’t in the history of any branch/tag, but it’s relatively easy to find
- nightmare: you need to search every single commit to find it
- disaster: it’s been deleted
how commits can get lost: git commit –amend
before:
Diagram of two boxes side by side, labelled “main branch”. The one on the left is labelled “parent
”. The one on the right is labelled “fix color buug
” (typo!).
after:
The same diagram as above, but the initial two boxes are now labelled “Now it’s “lost”!”. Also branching off of “parent
” is a third box, labelled “fix color bug
”. That branch is now labelled “main branch”.
how commits can get lost: git rebase
before:
Two boxes side-by-side, connected by a line. These are labelled “main branch
”. Also branching off of the leftmost box are two further boxes, one labelled with a heart, and one with a star. These are labelled “feature branch
”.
after:
An initial box with two lines of boxes coming off of it. The topmost line of boxes is a blank box, followed by a heart, then a star. The blank box is labelled “main branch
”. The heart and star boxes are labelled “feature branch
”. The lower line of boxes have a heart and a star and are highlighted in red and labelled “now these two are “lost!”.
how commits can get lost: git stash drop
before:
Three boxes in a horizontal row. The left two boxes are blank. The middle box is labelled “main branch
”. The rightmost box has a star, and is labelled “stashed commit
”.
after: The same diagram as above, but now the rightmost box is labelled “now it’s “lost”!”.
stash is the only way I’ve seen the “nightmare” situation happen.
you can find lost commits
I find it very comforting to know that git keeps my lost commits around. How to find them:
- annoying: use the reflog (page 26)
- nightmare: use
git fsck
- disaster: impossible (but this has never happened to me)
Saturday Morning Comics!
Want another comic like this in your email every Saturday? Sign up here!