Software Development

What The Commit!?

Committing in Git is The Future

Whatever you write in your git commit history is what you’ll be going back to at some point in the future to understand how the source code got to where it’s at now.

There are a couple of things that seem to work well when managing commits in git:

  • Don’t have more commits than tell the story – so squash commits on a feature branch into a single final commit before merging
  • Try to keep the tree clean – so rebase, or force master fast-forward merges, so the commit history of your main branch is a series of revertable individual commits
  • Make your commit message tell their story well

Let’s look at the last one – the perfect commit message.

The Imperfect Commit Message

Don’t blether. Don’t treat it with disrespect. Don’t just commit with the branch name, and definitely look at http://www.whatthecommit.com/ for inspiration on what bad looks like

I just got:

bumping poms

A Great Commit Message

Here are some guidelines:

  • Title the commit with a short, imperative statement, as though commanding the developer who made the change
    • E.g. “Add support for versioned schemata”
    • E.g. “Fix slow performance with multiple threads”
  • Optionally, add some narrative underneath, perhaps in bullet point form

Good Commit Messages

One Liner

1
Add cache to the schema loader to speed things up

Heading and Detail

1
2
3
Remove unused libraries
- commons lang no longer needed
- switch to default jackson in place of override

Bad Commit Messages

A Who Cares Message

1
Updated the code

WHERE’S THE TEXT?

1
Ticket #127

Vague and non imperative

1
Fixed bug

Non Imperative

1
Fixing the bugs reported by users in the calculation module

Essay

1
I decided to update the library version and put some notes in the README to that effect. This resulted in no obvious test failures.

Conclusion

Commit messages are only important when they’re important, at which point they’re mission critical. Getting your public commit history into a sensible shape, with pithy headlines, will give the optimum benefit to your future self and your code reviewers.

Published on Java Code Geeks with permission by Ashley Frieze, partner at our JCG program. See the original article here: What The Commit!?

Opinions expressed by Java Code Geeks contributors are their own.

Ashley Frieze

Software developer, stand-up comedian, musician, writer, jolly big cheer-monkey, skeptical thinker, Doctor Who fan, lover of fine sounds
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button