In which I share a crochet analogy for Git commits…
Don’t forget your stitch markers!
I am happily continuing my crochet learning journey. One lesson I have now internalised is that I should never ever forget or neglect to use stitch markers. Stitch markers are sort of small, not spiky, safety pins.
A crochet project featuring several stitch markers (beginning of a Snorlax from Lee Sartori’s Pokemon crochet book)
Stitch markers should be used:
- at the beginning of a round to not forget where it started – in amigurumi you often crochet in a spiral so it’s hard to know where a round started,
- every multiple of stitches to not have to count stitches above 12 even if you happen to have a PhD in counting1. Many crochet patterns will have you, say, “increase by two stitches every 8th stitch”, then “increase by two stitches every 9th stitch” so having your markers every 9 then 10 stitches will be most helpful.
I have sometimes forgotten to place my stitch marker at the beginning of a round, and really regretted my lack of concentration. Furthermore, I used to think that adding more stitch markers was too much work (Opening the marker! Putting it under a stitch! Closing the marker! Could I be any lazier?!) which is absolutely wrong. Stitch markers bring peace of mind. They spark joy.
Don’t forget your Git commits!
Well, Git commits are just like stitch markers. Putting them regularly along your strand of work will only help you in the future. It is well worth the small annoyance of making them. With good commits, you can undo your work up to a certain point. You can understand what was done when and why.
In the saperlipopette R package I’ve recently added exercises related to using history:
- “I want to find which commit deleted a file!" (
git log -- <path>) - “I want to find which commit deleted a line!" (
git log -S<string>,git log -G<regex>) - “I want to understand ancestry references!" (
git show,git rev-parse) - “I want to find who added a specific line!" (
git blame) - “I need to see what the project looked like at a certain version!" (
git worktree) - An older exercise: “Hey I’d like to find which commit introduced a bug!" (
git bisect)
Most of those exercises teach you the skill of obtaining a Git commit ID in answer to a question. How useful that is depends on how good the commit history is: big commits with uninformative messages are not great. If the exercises related to using the history seem relevant to you, try improving your commit history.
Note that you use conventional commits, you might even get nice colours for them, just as if you were using stitch markers! The above is due to RefinedGitHub, a browser extension for GitHub, but I’m sure similar functionality exist for other Git platforms and in IDEs.
Conclusion
In conclusion, I firmly believe good Git commits can change your life for the better, just like stitch markers. Don’t learn the lesson the hard way!
Besides, if you’re interested in learning how to recover from common Git mistakes such as a commit made on the wrong branch, consider registering to my upcoming workshop at Workshops for Ukraine: “Oops, Git! How to recover from common mistakes”, Thursday, March 19th, 14:00 - 16:00 CET (Rome, Berlin, Paris timezone). All proceeds going to support Ukraine. (After the workshop, making a donation gets you access to the recording)
-
Also called PhD in statistics! ↩︎