Friday, March 26, 2010

On commit messages

I would like to address the issue of commit messages. Good commit messages can make finding bugs and understanding the timeline of a project easy, and bad ones can result in an infuriating waste of time reading diffs and trying to locate information.

First of all, all commits should be atomic, that is they shouldn't include unrelated changes. Fixing a typo or spacing while fixing bug in related code is acceptable, but fixing 6 bugs and adding 2 features in the same commit makes it hard for people to parse out what change was for in the future. A good rule of thumb is that if a summary of your changes can't fit in one line, it's probably too big.

The first line of the commit message is most important part. This is especially true today, where many DVCSes only show the first line of the commit by default in their log command. The summary line should succinctly summarize what your change is and what it accomplishes. It need not be a full sentence, but just a bug number or general statement ("fix this") is not appropriate. The best summary lines quickly inform any log browser of the purpose and changes in the commit. Summary lines should also never be wrapped. Nothing is more annoying than reading a summary line which is cut off in the middle by a line break. Simple typo fixes do not require complicated messages. Good examples:
fix #2345 by preventing add() from accepting strings

fix a segfault in foo_my_bars() #4563

fix spelling

add a Python interface to the tokenizer #3222

and bad ones:
test and a fix

ugg

bah

a huge change to Foo class

why does this not work?

bug #4543


After the summary line can optionally come a body. A blank line should always separate the commit message from the body and different sections of the body from another. Bodies should also always be line wrapped. The body can include any of the following:

  • Bullet points describing various aspect of the change in more detail.

  • A paragraph description explaining why how something was implemented or why it's written a certain way.

  • A reference to mailing list discussions or decisions that lead to the commit.

  • Authors and attributions.

  • Any other significant information about the commit. For example, explain how it affects external components or might result in unexpected behavior.


Some projects follow the convention of listing affected files in bullet points and describing the individual changes to each. I personally find a prose summary of the changes in the body along with a diff or the verbose version of the log which shows changed files more helpful than this technique.
Good examples of complete commit messages:

"""
normalize encoding before opening file #3242

This change requires that tokenizer.c be linked with the Unicode
library.
"""

"""
silence foo warnings by default

Approved by BDFL in
http://mail.python.org/pipermail/mailinglist/bladh.html
"""

"""
support unicode in shlex module #4523

This is implemented by providing a separate class for Unicode and
requiring a locale to be set before parsing commences.

Patch by J. Hacker and J. Programmer
"""

"""
boost the speed of keyword argument comparisons

This improves some function calls by over 30% by comparing for
identity before falling back to the regular comparison. stringobject.c
was modified to provide faster access to a string's value.
"""

26 comments:

Anonymous said...

Thanks for posting this. It's good for novice as well as experienced programmers to review basics from time to time.

The unfortunate thing is that the people that most need to read and heed this never will.

Anonymous said...

It might also be helpful to point out that the "one line" should not be over five hundred characters long...

Not that I'm bitter or anything.

rajani said...

Thank you so much. It is a great article for me.
Django Online Courses
Django Training in Hyderabad
Python Django Online Training
Python Django Training in Hyderabad

sasi said...

This is a good post. This post give truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. thank you so much. Keep up the good works.

Python Training in Chennai

Keerthana said...

Thanks for your Ideas.Amazing Hints and Tips are sharing here about Python Training. Visit Once
python training in chennai | python training in annanagar | python training in omr | python training in porur | python training in tambaram | python training in velachery

3RI Technologies said...

Thanks for sharing the informative content, very helpful and eye-catchy content. Thanks for sharing. Python Training in Pune

Anonymous said...

Thanks for sharing I really appreciate your knowledge
thejacketzone

James said...

Thankful for sharing this post, It was vast looking at this article. I ought to research python course
keep in touch and stay related and guide us more.

kumar said...

This post is so helpfull and attractive.keep updating with more information...
Career In Data Science
Demand For Data Scientist

Hussey said...

Really nice blog. thanks for sharing
python training centre in chennai
best python institute in chennai

David Fincher said...

This post is so interactive and informative.keep update more information...
DevOps course in Tambaram
DevOps Training in Chennai

eMexo Technologies said...

Pretty Post! Thank you so much for sharing this good content, it was so nice to read and useful to improve my knowledge as an updated one, keep blogging.

Python Certification Training in Electronic City

That's King's House said...

Awesome Post. Thanks For This Article

Lookobeauty said...

great content

visit - https://interiordesignergurgaon21.blogspot.com/2022/08/how-to-use-color-in-interior-design-and.html

Anonymous said...

Your Article is very impressed for me, because of all information. Full Stack Course in Hyderabad.

JacobHarman said...

Made in August 2011, Blockchain is an organization that offers three center types of assistance. Their most memorable help, accessible from Blockchain.info, is a blockchain pilgrim that permits clients to investigate bitcoin exchanges and immediately check the situation with any bitcoin exchange. A little more than two years into the making of Blockchain.info, it turned into the most well known bitcoin site on the planet with 118 million month to month site hits and 3 million month to month remarkable guests. Besides, it has turned into a standard reference for bitcoin insights, and it is being utilized by well known monetary organizations like Reuters and Bloomberg for their reports>> blockchain app development services

shubhi pandey said...

Thanks for this article . Data Science Course in Pune

3ri Technologies said...


This post is very informative.Very nice post! If you have any specific questions or need more information about Python, feel free to ask. Come to Python Training in PuneIt is one of the quickly developing organizations and is tremendously liked by understudies for the nature of preparing given by them.Online and offline classes are provided here and it is the best institute in Pune

Decor Mirco said...

nice information very nice post
Diverse Dance
Party Summer
Party Football
Birthday 30th Decorations
Balloons Birthday

Bydnow-Build Your Dreams said...

Very informative article..
online java full stack developer course in warangal

vetri said...

nice article
internship for eee students

shubhi said...

This post is excellent. This post provides genuinely excellent facts. I will surely give it some research. Here are some really helpful pointers. I really appreciate it. Continue your fantastic job.
Python Course in Pune

John Fei said...

The digital transformation services offered by Attract Group truly stand out from the competition. Their expertise in utilizing cutting-edge technologies to drive business growth and innovation is remarkable. The team's dedication to understanding each client's unique needs and delivering tailored solutions is impressive. With a focus on creating seamless digital experiences and improving operational efficiency, Attract Group is undoubtedly a leader in enabling businesses to thrive in the digital age.

peacemedia said...

Good knowledge source. Thanks for the information.
stall designer

Digital said...

Great article! Clear and meaningful commit messages are often overlooked but are crucial for collaboration and maintaining a clean project history. They not only help team members understand changes quickly but also make future debugging and project scaling much easier. I especially agree with the point about keeping the message concise but descriptive—finding that balance can really streamline code reviews and improve workflow. Thanks for sharing these tips!"

Digital Marketing Course In Hyderabad

FULL STACK DEVELOPER IN HYDERABAD said...

"Great article! Writing clear and meaningful commit messages is often overlooked but so essential for collaborative development. This post perfectly captures why good commit messages matter and offers practical tips to improve them. Thanks for the valuable insights!"
react training in hyderabad