My favorite commit message is just two words.
Git Commit Message : I use version control – Git, for the most part – all the time, even with little scripts no one will ever look at besides me, even when I probably don’t need to. I just like it. Something about using version control or source code management or whatever you want to call it makes my coding process smoother.
And I noticed something interesting, committing code into some repository or another almost every single day for the last several years. I have one commit message I use over and over and over.
It’s this: “code compress”
All lower case, just like that.
That’s kind of a shorthand… I’ll explain. Imagine I have code that’s already working. Has unit tests, probably (though maybe not enough of them… another topic). But it has unit tests which are passing, or maybe it doesn’t, because the script is simple and I’m just testing manually.
So I’ve added the changes to the repo and committed already. It’s committed in a (partially) working state.
Then, I make it better.
What do I do? I rename variables, functions and methods, so it’s more readable (understandable) when myself or a teammate are modifying this 11 months later and don’t remember what was in our heads back then. I take five or 20 or 100 lines of code, and I simplify it. So that it becomes two or seven or 35 lines. Whatever I can cut out.
No new features. Zero progress on functionality. I simply make the code more readable, maintainable, or otherwise better. It went from one working state, to another, equivalent working state. A completely horizontal move.
And then I git-add and git-commit. With the message “code compress”.
Often this makes the code base smaller, in terms of lines-of-code. In a way that (importantly) is more readable and maintainable. But still works just as well.
More elegant, in other words.
But not always. The actual change set doesn’t *have* to reduce the lines of code. If I’m changing the names of identifiers, that has basically zero effect on the code size. Heck, I may take an obscure dozen lines and in the process of de-obfuscating it, now it’s something like 80, or 200. So I’m not always actually compressing the code.
But regardless, it’s an improvement.
This is great to do in your own private branch, where you can make a zillion tiny commits and no one will give you a hard time about it. Sometimes I’ll have three “code compress” commits in a row.
I do this so often, so frequently, that I just settled on the phrase “code compress” so I don’t have to think about what message to write. There’s probably a better name for it. But I can’t be bothered to change that habit. That takes willpower, and I have other habits that are more important to change.
But maybe you get the idea.
What is great about this concept:
Just knowing you can use “code compress” as a commit message,
automatically gets you thinking about how you can continually IMPROVE
Try it today. Because you will love the results.
The Powerful Python Newsletter is just for you. Like reader Charles Hayden puts it:
“I have seen a lot of books, articles, and newsletters over the years and yours is one of the best. Not just what you say about Python, but how to go about learning.”