Home » Software Development » What The Commit!?

About Ashley Frieze

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

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.

(+1 rating, 1 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy
Subscribe
Notify of
guest

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

0 Comments
Inline Feedbacks
View all comments