4

I know it's not to be opinionated here but my question is, what is a good way of writing concise commit messages?

I've been using Git (SmartGit, SourceTree) for a couple of months now and as I'm getting more used to it, I'm starting to realize that my commit messages are not clear or detailed enough for history viewing i.e. I'm falling in my own tracks.

So far I've been writing my solution like "Work in progress/done: yadayada.." but even so it feels I could do this better. Anything is welcomed :)

P.S. I do a lot of front-end (html, css, js).

/P

moller.peter
  • 105
  • 2
  • 11

3 Answers3

18
Separate subject from body with a blank line
Limit the subject line to 50 characters
Capitalize the subject line
Do not end the subject line with a period
Use the imperative mood in the subject line
Wrap the body at 72 characters
Use the body to explain what and why vs. how

Source : http://chris.beams.io/posts/git-commit/

This post got all you need ! :)


This "Use the body to explain what and why vs. how" is the most important thing. Devs usually just explain how they fixed a problem they faced; a commit is to know what has been done, not how it has been done.

Alexandre Beaudet
  • 2,774
  • 2
  • 20
  • 29
  • 1
    I think it's noteworthy that item 5 (Use the imperative mood) is very opinion-based (at best) and ground for religious wars (at worst). See for example these 2 questions, [here](http://stackoverflow.com/questions/1753808/should-commit-messages-be-written-in-present-or-past-tense) and [here](http://stackoverflow.com/questions/3580013/should-i-use-past-or-present-tense-in-git-commit-messages) – Fabio says Reinstate Monica Oct 13 '15 at 12:47
  • Well most of it is kinda opinion based... But I think that Git itself tells people to use imperative for the commits, so I guess it is a good way to go ! (EDIT : Actually just seen in one of the answer that git did; obviously it's not a rule but it's a common preference) – Alexandre Beaudet Oct 13 '15 at 12:50
2

Basically, you should write what you've done in your commit. Like if you were creating user auth in your app, usually, you wouldn't commit every single controller's method, model, view's parts etc. You should add everything you've done for your task and commit it as a single commit.

pavjel
  • 486
  • 10
  • 25
1

The way I do it is the following:
Title:
ANDR-10500: Refactored the Database error messages.

Commit Message:

Why:
In order not to have duplicates error messages in many classes, I centralised all of them in one big class that can be accessed from everywhere and also can extended whenever is required(for different modules/libraries), etc, etc.

What did you do:
I refactored all the error messages from all the database class into one class that contains all the errors that can possibly happen. The class is a singleton class, etc, etc.

Andrei T
  • 2,985
  • 3
  • 21
  • 28
  • 1
    The git documentation (https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project) says to use imperative mood for the verb in the commit message, and in their example they don't end the message with a period. From that link: "Write your commit message in the imperative: "Fix bug" and not "Fixed bug" or "Fixes bug."" – dcp Feb 04 '21 at 13:12