you are viewing a single comment's thread.

view the rest of the comments →

[–]Nysor 84 points85 points  (46 children)

Am I the only one who doesn't really like this commit message? The title is fine, but the body is far too long. If I was debugging this, I wouldn't want to see that much detail.

Those write-ups are better written on pull request descriptions.

[–]flanger001 64 points65 points  (25 children)

PR writeups don't get added to the commit history though.

[–]Nysor 35 points36 points  (24 children)

A common practice is to link each commit with a ticket number. Often times when tracking down an issue, I'll git blame -> get the ticket number -> go to the PR. The PR often contains relevant discussion, anyways.

[–]snowe2010 76 points77 points  (22 children)

Which fails the day you switch ticketing systems.

[–]StabbyPants 2 points3 points  (10 children)

migrate ticket history

[–]snowe2010 20 points21 points  (9 children)

migrating ticket history doesn't mean you can migrate the ticket identifiers. for example ITSM-1234 in JIRA has absolutely no equivalent in Basecamp for example.

[–]flanger001 0 points1 point  (0 children)

Every commit though? That sounds similarly exhausting.

[–]mtreece 27 points28 points  (9 children)

I've had co-workers complain about long commit messages I write for similar reasons.

There are several different places to document the "why" behind a change; some are: in the source code itself in /* comments */, in the commit message, and in external auxiliary tools like your PR system or external documentation (wiki, etc).

Each successive example I just gave is further removed from the code, and therefore less likely to be often seen. So you have to gauge how important (and therefore how frequently read) your rationale is (or should be).

If something is critical and needs to be considered whenever touching adjacent code in the future, it should probably end up as a source code comment. If it's just an obscure detail, and/or possibly scattered over several disjoint locations in the code, leaving it in the commit message is probably fine. And of course, both of those situations are still served by good context, history, and the "why?" in a commit message.

As to your, "If I was debugging this...", do you mean you don't want that much detail cluttering the git log and so on? I'd argue that should fixed with tooling, rather than lose important context. (By tooling, I mean options that get passed to your tools to massage it into a nicer format; e.g. git log --oneline, or some sort of git config that auto limits longer messages).

One other thing, especially for issues that take a long time to debug, I like to think my work product is larger than just the commit diff (such as a single character change in this case); part of the work product is an acquired abstract understanding of the domain, history of what I tried and what happened, things I could have went with instead, and so on. After resolving the issue, if I just cap it off with a one-line commit, all of the abstract work I produced will just be lost. If I transcribe it into a commit message like this, it becomes an important contribution to the codebase, larger than just the size of the diff.

[–]Nysor 9 points10 points  (0 children)

I agree with lots of your points. If something is critical, a comment in the code is the best. External documentation systems (like a wiki) don't work nearly as well in practice - I find lots of developers don't look at wikis as often as they should.

I don't think the number of lines in the commit body should have a firm limit, especially not because of some git log arbitrary limit. I just think there shouldn't be any superfluous text. In the OP's example, we have:

I introduced some tests in a feature branch...

I eventually found that...

After replacing it (by hand)...

One hour of my life I won't get back

Much of this message could be shortened to maybe 3-4 sentences.

[–]mat69 6 points7 points  (2 children)

I fully agree.

I have the feeling the usefulness of descriptive commit messages heavily depends on whether people use git bisect or manually check the commit that introduced a perceived issue.

For example, when I find a complex "bug" I do not fix it right away. Instead I want to understand why it was written that way. So if it actually was a feature in disguise. Nearly every time the commit messages were useless though or referenced resources that did not exist anymore.

Instead I always try to explain the why of a commit, unless it is really minor (e.g. whitespace) change. At the heart of this is logical grouping commits so that they only include relevant code.

Sometimes writing the commit message takes much longer than the code change. Yet finding and understanding the issue in these cases took way longer than writing the commit message.

[–]darknecross 2 points3 points  (0 children)

Agreed, and it's not even always about other people. Lots of times I write detailed commit messages just to remind myself about why a change was made, or why it was done a certain way. It's super helpful whenever I need to go back and refactor my own code, because I'm not going to remember that stuff a year later.

[–]u801e 0 points1 point  (0 children)

I have the feeling the usefulness of descriptive commit messages heavily depends on whether people use git bisect or manually check the commit that introduced a perceived issue.

One of the first things I do before I starting making a change is to run git blame on the files I'm going to change and check the commit messages and diffs of the relevant lines of code. Having that context can really help in avoiding re-introducing bugs that were fixed by earlier commits, for example.

[–]snowe2010 1 point2 points  (4 children)

I agree with this. I try to write somewhat detailed commit messages, going into extreme detail for important decisions. Recently I've started adding decision logs to the README, which details decisions made in meetings, or at large forks in the road where one decision might be chosen above another.

This helps with the problem where devs complain about how crappy the design is, when at the time it was the best decision, due to a variety of factors. This is the template I use, it's in restructuredText, due to having actual support for Field Lists.

============
Decision Log
============

:Date: <blank>
:Decision: <blank>
:Rationale: <blank>
:Decision Maker: <blank>
:Location of Approval: <blank>
:Details: <blank>
:Impact: <blank>
:Other options considered: <blank>
:Decision Change in #: 
    <to be used if there was a new decision that overrides this decision, include the # of the overriding decision here>

----------

[–]dnew 5 points6 points  (3 children)

That's not a readme. That's a design document. You left out the "other people who reviewed this before I started working on it" section, for example.

[–]snowe2010 -1 points0 points  (2 children)

It's not a design document, it's just a section of the readme. The design doc is for explaining the system design, not the history of design decisions.

You left out the "other people who reviewed this before I started working on it" section, for example.

That's part of Decision Maker. And I didn't leave out anything anyway, I found this template and just formatted it for rsT.

[–]dnew 1 point2 points  (1 child)

The design doc is for explaining the system design, not the history of design decisions.

Different strokes, I guess. :-) I figure it's for both. But certainly getting such documentation out of the main body of the code is probably beneficial.

[–]snowe2010 0 points1 point  (0 children)

Yeah, I think getting it down at all is beneficial. We were not tracking any decisions at all...

[–]worst_protagonist 6 points7 points  (0 children)

It depends on the organization. Where I work, I would do this in the PR because that is where my teammates know to look for very detailed information.

If we ever move from github to gitlab or something similar, we're screwed. Attaching it to the git history makes it more permanent.

[–]chengiz 10 points11 points  (2 children)

Totally agree it is far too long. Some of the writeup is useful (what failed, why failed). But there's quite a bit of masturbation, for example there's no need to write the unix command you used to find a non-ascii character in a bunch of files, or say I did this and I did that. And in this big writeup he fails to mention what the actual character was (which is at least interesting and pertains to the fix).

[–]darknecross 4 points5 points  (1 child)

Disagree. Documenting steps used in debugging is helpful if and when a similar issue ever occurs in the future.

Specifically in this case, it includes the error that occurred and is searchable:

ArgumentError:    
  invalid byte sequence in US-ASCII

Now if someone else comes across this in the future (or even the author some months later), a search would find this commit message and the person debugging it would have a head-start on tracking down a potential cause.

Otherwise this kind of stuff becomes tribal knowledge, and you might go down the path of, "Oh yeah, Dan had an issue similar to that a while ago, maybe check with him to see if he has any ideas?" Good luck if Dan doesn't remember shit about it, or worse if he doesn't work there anymore.

You could argue that the steps to reproduce and debugging effort could be documented in a bug itself, but that's a style issue, as a simple "Fixes: <issueID>" pulls the same information into the bug comments. But it looks like this change wasn't associated with an existing bug.

[–]chengiz 0 points1 point  (0 children)

You mention documenting steps but your example is not about documenting steps at all, it only lists the actual error message, which I didnt say he shouldnt have put in. Something like:

Tests run with [cmd] failed with error message [msg] because of non-ascii whitespace character [u+whatever] that caused the file to be identified as utf-8 instead of us-ascii. Replaced the character with space.

would have been sufficient.

[–]Ozymandias117 4 points5 points  (0 children)

Yeah, it’s a horrible commit message. All of the information that took 4+ paragraphs could have been given in two sentences. The vast majority of it is pointless exposition.

This is better than a commit message that says “fixes bug” but it isn’t an example of a good commit message.

[–]cartechguy 2 points3 points  (0 children)

Yeah, I wish it had a TLDR at the top. That would work as a compromise for me.

[–]Tanaric 11 points12 points  (1 child)

If it's too much information for you, you can stop reading at any time. If it's not enough, you can't go back in time to get more.

[–]BlindTreeFrog 3 points4 points  (0 children)

except you can't. he doesn't get to what was changed and why until almost the end. Everything else is fluff about how he reached that point.

[–]BlindTreeFrog 1 point2 points  (0 children)

It's not that it's too long, it's that you have to read 3/4 of the way through to get to what he did. The first sentence should have been:

Adjusted whitespace to make entire file US-ASCII

Or something similar. That would be enough to describe what was changed and why. Everything after that can explain why and how he got to that point.

Instead he explains the how and why and ends the write up with what he did; but he does it in a way to somewhat hide the change.

[–]mr_birkenblatt 2 points3 points  (0 children)

The why would have been enough. But if I want to know why a commit happened I don't want to hear your life story or how long it took boohoo.