1e01aa904Sopenharmony_ciGit commit messages format 2e01aa904Sopenharmony_ci========================== 3e01aa904Sopenharmony_ci 4e01aa904Sopenharmony_ciThe principle of the git commit log is to document at least the 5e01aa904Sopenharmony_ci*what*; in English. That is redundant with the commit diff, yes. But 6e01aa904Sopenharmony_cithat redundancy does help in understanding the commit diff better. If 7e01aa904Sopenharmony_ciappropriate, the commit log can also document the *why*, but only if 8e01aa904Sopenharmony_ciit does so by respecting the format of the commit log. The reason why 9e01aa904Sopenharmony_ciwe are so strict about the format is that the commit log is later 10e01aa904Sopenharmony_ciparsed by a tool to build a ChangeLog, which we want to stay compliant 11e01aa904Sopenharmony_ciwith the GNU ChangeLog format. 12e01aa904Sopenharmony_ci 13e01aa904Sopenharmony_ciSo here is the format we are talking about. 14e01aa904Sopenharmony_ci 15e01aa904Sopenharmony_ciThe first line of a git commit message should start at column 1, with 16e01aa904Sopenharmony_cino space. That line should be a short summary of the purpose of the 17e01aa904Sopenharmony_cicommit. If the commit relates to a bug filed into bugzilla, the line 18e01aa904Sopenharmony_cishould begin with the bug (or Problem Report) number, followed by a 19e01aa904Sopenharmony_ciwhite space; e.g: 20e01aa904Sopenharmony_ci 21e01aa904Sopenharmony_ciBug <number-of-the-bug> This is a great commit 22e01aa904Sopenharmony_ci 23e01aa904Sopenharmony_ciThe line in its entirety should not be longer than 50 characters. 24e01aa904Sopenharmony_ci 25e01aa904Sopenharmony_ciThe next line should be an empty line, with no spaces. 26e01aa904Sopenharmony_ci 27e01aa904Sopenharmony_ciSubsequent lines can be a free form introductory text that should 28e01aa904Sopenharmony_cistart column 0. The introductory text can have an arbitrary number of 29e01aa904Sopenharmony_cilines. No line in that text should start with the sequence 30e01aa904Sopenharmony_ci<white-space>*. That is, no line in that text should start with a 31e01aa904Sopenharmony_cisequence of white spaces followed by the start character (*). 32e01aa904Sopenharmony_ci 33e01aa904Sopenharmony_ciIf there was an introductory text, then the next line should be an 34e01aa904Sopenharmony_ciempty line, with no spaces. 35e01aa904Sopenharmony_ci 36e01aa904Sopenharmony_ciThe subsequent lines should have the form of the Body of a GNU ChangeLog 37e01aa904Sopenharmony_cientry, i.e: 38e01aa904Sopenharmony_ci 39e01aa904Sopenharmony_ci * file1.c (func1): Changed foo in this function. 40e01aa904Sopenharmony_ci (func2): Changed blah in that function 41e01aa904Sopenharmony_ci * file2.c (func_foo): Changed something here. 42e01aa904Sopenharmony_ci 43e01aa904Sopenharmony_ciNote that before the '*', there is a tab that is 8 spaces long. Also 44e01aa904Sopenharmony_cinote that right after the '*', there is a space. 45e01aa904Sopenharmony_ci 46e01aa904Sopenharmony_ciAn example of commit message would be: 47e01aa904Sopenharmony_ci 48e01aa904Sopenharmony_ci~=~ 49e01aa904Sopenharmony_ciBug 123456 Add super feature 50e01aa904Sopenharmony_ci 51e01aa904Sopenharmony_ciThe super feature requires modifying function_bleh to make it call 52e01aa904Sopenharmony_cifunction_foo instead of function_bar. As function_bar is no more 53e01aa904Sopenharmony_ciused, this patch removes it. 54e01aa904Sopenharmony_ci 55e01aa904Sopenharmony_ci * file1.c (function_foo): Define new static function. 56e01aa904Sopenharmony_ci * file2.c (function_bar): Removed static function. 57e01aa904Sopenharmony_ci * file3.c (function_bleh): Modified this function to call 58e01aa904Sopenharmony_ci function_foo, rather than function function_bar. 59e01aa904Sopenharmony_ci~=~ 60e01aa904Sopenharmony_ci 61e01aa904Sopenharmony_ciNote how, in the ChangeLog part of the commit log, each function 62e01aa904Sopenharmony_cimodification is mentioned, by referring to the name of the function in 63e01aa904Sopenharmony_ciparenthesis. The length of a line should not exceed 72 characters. 64e01aa904Sopenharmony_ciThe description of what happens to the function should be succinct. 65e01aa904Sopenharmony_ciJust describe the "what". 66e01aa904Sopenharmony_ci 67e01aa904Sopenharmony_ciThe "how" should be described by comments in the code change itself, 68e01aa904Sopenharmony_ciso there is no need to describe in the ChangeLog part of the commit 69e01aa904Sopenharmony_cilog.. The "why" and "general spirit" of the change should be 70e01aa904Sopenharmony_cidescribed in the introductory text that precedes the ChangeLog part. 71e01aa904Sopenharmony_ciSo, again, no need to add to the ChangeLog part. 72e01aa904Sopenharmony_ci 73e01aa904Sopenharmony_ciFor files that contain no function definitions, the ChangeLog looks 74e01aa904Sopenharmony_cilike: 75e01aa904Sopenharmony_ci 76e01aa904Sopenharmony_ci~=~ Bug 123456 Shorten compilation lines 77e01aa904Sopenharmony_ci 78e01aa904Sopenharmony_ci * configure.ac: Shorten compilation lines by regrouping 79e01aa904Sopenharmony_ci PKG_CHECK_MODULES calls. 80e01aa904Sopenharmony_ci * tests/Makefile.am: Adjust this. 81e01aa904Sopenharmony_ci~=~ 82e01aa904Sopenharmony_ci 83e01aa904Sopenharmony_ciAnother one could be: 84e01aa904Sopenharmony_ci 85e01aa904Sopenharmony_ci~=~ 86e01aa904Sopenharmony_ciBug 123456 Shorten compilation lines 87e01aa904Sopenharmony_ci 88e01aa904Sopenharmony_ciBlah blah, this is an introductory text explaining the purpose of this 89e01aa904Sopenharmony_cicommit. It can contain whatever character I want. It just cannot 90e01aa904Sopenharmony_cicontain a line that starts with white spaces immediately followed by 91e01aa904Sopenharmony_cithe star character. 92e01aa904Sopenharmony_ci 93e01aa904Sopenharmony_ci * configure.ac: Shorten compilation lines by regrouping 94e01aa904Sopenharmony_ci PKG_CHECK_MODULES calls. 95e01aa904Sopenharmony_ci * tests/Makefile.am: Adjust this. 96e01aa904Sopenharmony_ci~=~ 97e01aa904Sopenharmony_ci 98e01aa904Sopenharmony_ciWhen it's needed, the introductory text is very important. Please 99e01aa904Sopenharmony_citake time to explain the current status of the code (before your 100e01aa904Sopenharmony_cipatch) and why it was in the need of your patch. In other words, take 101e01aa904Sopenharmony_citime to explain the problem you are trying to solve. If the problem 102e01aa904Sopenharmony_ciis explained in a bug in the bugzilla, please try to explain it again, 103e01aa904Sopenharmony_ciusing your words. Just linking to the bugzilla is generally not 104e01aa904Sopenharmony_cienough. And then, yes, refer to the bugzilla. 105e01aa904Sopenharmony_ci 106e01aa904Sopenharmony_ciThen explain how your changes address the issue that you've just 107e01aa904Sopenharmony_cidescribed. 108e01aa904Sopenharmony_ci 109e01aa904Sopenharmony_ciIn other words, the introductory text should tell a story. So please 110e01aa904Sopenharmony_cibe generous :-) 111e01aa904Sopenharmony_ci 112e01aa904Sopenharmony_ciAnd then the ChangeLog part of the commit log is another exercise. 113e01aa904Sopenharmony_ciThis one has to be succinct. Every single function or global variable 114e01aa904Sopenharmony_cior type changed (or added/removed) has to be mentioned explicitly by 115e01aa904Sopenharmony_ciname as shown in one of the examples above. 116e01aa904Sopenharmony_ci 117e01aa904Sopenharmony_ciWriting the ChangeLog part of the commit log can seem tedious, but 118e01aa904Sopenharmony_ciit's an excellent way to perform an auto-review of your work. You'd 119e01aa904Sopenharmony_cibe surprised by the number of issues that you catch in the process. 120e01aa904Sopenharmony_ci 121e01aa904Sopenharmony_ciAlso, please keep in mind that reviewers of the code are going to do a 122e01aa904Sopenharmony_cifunction-by-function and line-by-line review of your changes, so 123e01aa904Sopenharmony_ciplease, take the time to do so as well. This is a great way to give 124e01aa904Sopenharmony_cigreat quality to your code. 125e01aa904Sopenharmony_ci 126e01aa904Sopenharmony_ciWe encourage you to look at the existing commit logs or at the 127e01aa904Sopenharmony_ciChangeLog file for inspiration. 128e01aa904Sopenharmony_ci 129e01aa904Sopenharmony_ciHappy Hacking! 130