by markrages · 3y ago · 0 comments
It is almost like signing all your commits with your name or the current date. (Yes, I had a coworker who did this.)
Better commit messages tell you what the situation was around the commit: Ticket number, or who wanted the change, or any other context that might tell you why the code was changed the way it was.
Consider the dev accessing your commit through "blame". What does that user need to hear? Not which file or subsystem was changed. But the reason there is a change in the first place.
My habit has been to prepare longer commit messages, a paragraph or two of explanatory text for that future developer, who is most likely future me.
Policy at my company now squashes all my carefully-prepared commit messages into the one-liner "Merged $BRANCHNAME into main". I will probably just switch to the three character commit message "WIP" like my coworkers have done.
- GitHub uses the pull requests title and description as the merge commit description, as well as linking to the pull request. This means all of our mainline commits now have links to relevant Jira tickets, context, change requests, and feedback on the PR. - The mainline commits are new linear and easy to read through, to the point where I was able to make an internal tool that can show everyone where every commit is at, with a nice description, and what stage in the production release cycle it’s at. - git bisect is a lot easier now. No one has to bissect through all kinds of “wip” or “fixed test for x platform in ci” commits. - most devs never have a need to rebase. Ever. This means devs can stack PRs against each other and test each others code together without having to deal with a rebase causing a bunch of pain. - All commits in our main branch now pass CI. - all commits in our main branch are now GPG signed by the org, without devs needing to configure commit signing locally.
So I prefer the flow of rebasing before merge. This way main stays linear and readable and you have the descriptive level at the commit level. The Context for the full merge can be found in the ticket corresponding to the change.
Sounds like the perfect use of an inline comment rather than change history?
On the other hand the worst offenders are refactorings with the commit message "refactoring". Then you can go hunting. Then a comment would have helped.
In a perfect world we would have both, good inline comment, well written commit message and a ticket with more than a title.
After first line you can write all the additional information.
// if ID exists in commits
if (commits.has(id)) {
Big sigh every time I see this, especially if the code is "well-commented" // if ID exists in commits
if (commits.has(id)) {
// make no changes
return
}
// add ID to commits
commits.add(id)
// log ID to console
console.log(id)
On the other hand, LOCs through the roof, 10x developer right here.I don't understand what is so appealing about a linear commit history. It's a fabrication of reality, and I have never been grateful for it, only enraged.
Why wouldn't you want to know what _actually_ happened? What is being gained besides an aesthetically pleasing "commits" tab on GitHub?
There is never reason to squash. The best of both worlds is to always force a merge commit (disable fast-forward merges) and look at the log formatted whichever way you want (--first-parent shows people that linear history without destroying history).
Squashing large number of commits is questionable practice, though.
1. you can have a linear history by rebasing then fast-forwarding onto the target
2. but it’s complete nonsense, learn your tools e.g. `git log --first-parent` (and how to merge), merge commits work perfectly fine
3. and importantly you can rebase then merge, which cleanly packages a set of changes behind a single merge commit without interspersing with other branches, and yet without losing the branche’s details
That sentiment is not IMHO a particularly potent argument for _anything_ related to engineering.
Accuracy, not convenience, should be the goal. If you need to make consuming the data more convenient, that should be the focus.
To be clear using the word "correctly' is putting a lot more confidence behind my opinion than I ever intended, i.e. I am open to counterpoints, and do not portend to think a one size fits all policy is realistic.
There's also "git log --merges" but that would presumably show any merge commits that happen to be present in a branch that is being merged so it wouldn't necessarily be linear.
If you disallow merge commits on GitHub, does that prevent a merge commit from being introduced as part of a rebase merge? If it doesn't, then presumably the only way to guarantee a linear history on GitHub is to allow only squash merging.
So, if you don't trust your developers to always do the right thing perhaps you should either only allow merge commits or only allow squash merging?
And those below-average developers probably aren't looking at the history at all anyway.
At any time, a developer might make another branch, then merge branches or squash the whole history of their branch or create a new branch and add the changes as if it was a fresh branch. Meaningful history is lost in those cases as well. Adding micro-managing process might get (more or less) predictable results, but it almost always pushes developers toward anti-patterns ensuring those predictable results are not what was intended.
This doesn't mean a "why" shouldn't also be required.
Finally, I really dislike the specifics of conventional commits. "feat", "fix", and "docs" are not particularly interesting distinctions. Just put whatever you were going to put in parens and save yourself 6 bytes.
WTH? That’s the dumbest policy I’ve ever heard of. Who made this up?
On the other hand, a branch name can be 255 characters, time to get the entire thing in there.
I think they are more medium quality commit messages, low value would be significantly less informative than that.
Aside from that while I agree you should have ticket number etc. integration between ticketing system (generally Jira, let's be honest) and your git provider is probably non-existent so it is of less real value in finding what you what to find when looking through that git providers interface.
In fact if your commit message does not say what was done you will have to go into the commit to read the code and figure it out, which obviously is wasteful if you are trying to find the most likely commit in a dozen that caused a problem.
Doesn't that belong in the code itself? Do we really want the intention of a change to sit under multiple levels of blame?
Yes? How would you encode the reasons for a change and for the way the change was implemented in code, dozens of lines of comments and ending up with files which are 90% comments floating in the void long detached from any code they were relevant to (and which may not even exist anymore)?
A commit can certainly have computer readable metadata I presume!
Of course it can.
> which is primarily about succinct human understanding and setting context.
You do know there is essentially no limit to how long a commit message is right?
many repos are successfully using conventional commits in a way that's not low value, clear and concise in message, and useful in blame and walking history.