Email or username:

Password:

Forgot your password?
Darius Kazemi

I've got a new blog post up at Meedan (where I work). It's about longform git commits: what they are and how they can make your life as a software developer easier.

My spiciest git take is you should ban "-m" from your git repertoire and go full verbose invoking a text editor from the CLI to write commits.

meedan.com/blog/how-to-write-l

37 comments
vx. size_t queen grace :qvp:

@darius I can't write a commit any more without using commit -v, it's so good

keithzg
@BestGirlGrace @darius I'm legitimately a bit confused because I never use -v, I just use `git commit` and the diff pops up in my text editor ready for me to write a nice verbose commit message, as is my wont. Do people routinely change repo or local settings to make `-v` necessary?
keithzg
@BestGirlGrace @darius Ohhh sorry I see, the *full* diff. I suppose variable autocompletion would be nice! I tend to trawl through `git diff` as a step beforehand so seeing the specifics of the diff didn't even occur to me, heh, whoops.
keithzg
@BestGirlGrace @darius Absolutely do the 2 or 3 tier approach to my commit messages as described here, with the modification that I generally acquiesce to the standard form at my work where we put the bugtracker issue ID at the start of a commit. Unfortunately most of the computer engineers at my work will put *just* that issue ID with maybe some very terse "description", like

> BugID:999 - Commit fix

which means reading back through the commit log *requires* cross referencing our bugtracker.
@BestGirlGrace @darius Absolutely do the 2 or 3 tier approach to my commit messages as described here, with the modification that I generally acquiesce to the standard form at my work where we put the bugtracker issue ID at the start of a commit. Unfortunately most of the computer engineers at my work will put *just* that issue ID with maybe some very terse "description", like
Stacey Campbell

@darius To answer the eternal question "what on earth were they thinking?"

Aram Zucker-Scharff

@darius I'm already a long git commit message writer so this looks like very much my jam!

colin mitchell

@darius git -v was a real life-changer for me, love it

Emacsen

@darius

What I like about this is that it combines good editing practice in multiple layers.

The first line (what you're calling the subject line) of a git commit message really aught to be a simple "<verb> <subject>", but then you're right that there's room for more detail.

I'm still struggling to get some devs to perform good commit messages.

mcc

@darius Weird take: I very occasionally use -m with mercurial (I believe single line commit messages are almost never a good idea, but sometimes I do things that are not a good idea) but I NEVER use -m with git because it is completely baffling to me what files do and don't get included on any one git commit and entering the editor is the one surefire way to be CERTAIN you know what it is you're committing...!

Darius Kazemi

@mcc Yeah that is one of the main reasons I avoid -m so that tracks. Cool that mercurial does not share that problem.

alexandra catalina

@darius coworker suggests adding a bit on how to change your default editor! probably a lot of people are scared of being tossed into vi

Darius Kazemi

@catalina I think by default it will actually pull up a little picker that lets you pick between vi, nano, and some other ones but... yeah people should have vscode or whatever as an option too haha

Darius Kazemi

@catalina anyway, updated the post with a hyperlink to a how-to on changing the default. thanks for the prod!

Scott Feeney

@darius I tend to put those longform descriptions in pull requests, but I see how it could be valuable to have them in the commit message.

When you say ban "-m", surely you mean except for WIP/checkpoint commits that will be rebased/squashed later, right?

Darius Kazemi

@graue yes, correct on -m.

What I like about having this in git is that it stores the important information in git rather than in github dot com

Max

@darius @graue If you require merge commits, the description of the PR gets copied into the merge commit message. It’s another reason why I personally don’t understand the Rebase/Squash lifestyle: use merge commits and that PR description you put a lot of writing in on github gets nicely copied into your git history.

(Plus then you can use tools like —first-parent with merge commits.)

Darius Kazemi

Here's the part where I say, "by the way we are hiring a backend engineer with Rails experience and a machine learning engineer" please come work with me and make nice long commit messages:

meedan.com/jobs

Ed Summers

@darius very much enjoyed that, and learned about -v which is going to save me keystrokes and focus in the future!

Michael McClimon

@darius You probably know this, but you can set commit.verbose true in your config and never have to remember -v again! This is also really useful because you get it mid-interactive-rebase, when it’s a little harder to pass -v manually.

CMDR Yojimbosan UTC+(12|13)

@darius I'm still laughing at providing multiplication by dividing by the inverse of the operand ...

Darius Kazemi

@yojimbo thank you I'm very glad at least one person found that as funny as I did 😂

Sven "DrMcCoy" Hesse

@darius I generally agree, but I have a caveat to add there

When you feel the urge to write a lot in the commit message, a part of it should probably go into a comment in the code instead, so that the reasoning behind a piece of code is directly accessible there

Description why/how something *is* -> code comment
Why something was changed -> commit message

Darius Kazemi

@DrMcCoy I've found myself moving away from verbose comments in projects where commits are verbose - the understanding becomes that every line of code has rich metadata you can inspect via git blame etc. Still not sure where I land on the correct distribution of information.

Sven "DrMcCoy" Hesse

@darius I see the git history as something that might not always be available. For example, when generating a classic tarball with automake's make dist, the .git directory is usually stripped off

I run Gentoo on my personal machines. I more than once had to investigate why a package suddenly broke compilation on an update (especially when I have set an uncommon set of USE flags). I usually have to dive into the code there and that's usually from a release tarball without git repo

Daniel Gibson

@darius @DrMcCoy
It's probably untrve or sth as it's not CLI, but I really like git gui for committing. I can easily review my commit while writing the commit message, and unstaging that debug printf() that slipped in is just as easy, without having to abort the committing/writing commit message process.

And yes, commit message that contain actual information are super helpful and everybody should write them that way instead of "Fixed #123", referencing some bugtracker that might be gone next year

@darius @DrMcCoy
It's probably untrve or sth as it's not CLI, but I really like git gui for committing. I can easily review my commit while writing the commit message, and unstaging that debug printf() that slipped in is just as easy, without having to abort the committing/writing commit message process.

L.J. but extra nerdy

@darius Great stuff! Magit, the Emacs Git client, actually has verbose commit messages as the default which is one way it encourages good practice, it seems.

Mark Stosberg

@darius Yes. I encourage a #git commmit message body format of "Before, …
Now, …
Issue: CMO-123"

Jeff Ward

@darius This is why I just don't use the command line. My UI has that second box and it's just begging me to use it....

Darius Kazemi

@fuzzybinary "UI" huh... I'll have to research what that is...

Go Up