@@ -63,11 +63,15 @@ Keep hacking until the tests pass.
6363
6464Committing your work will save the change I<on your local system>:
6565
66- % git commit -a -m 'Commit message goes here'
66+ % git commit -a
6767
68- Make sure the commit message describes your change in a single
69- sentence. For example, "Fixed spelling errors in perlhack.pod".
68+ C<git> will open an editor (a default one, or the one you have
69+ configured it to) for you to type in a commit message that describes the
70+ change. When done, save and exit.
7071
72+ It is important for the smooth functioning of the project, both now and
73+ in the future to write a good commit message. This is covered below in
74+ L</Commit message>.
7175
7276=item * Submit your change to GitHub
7377
@@ -268,17 +272,100 @@ build artifacts, or you may get a confusing result.
268272
269273=head3 Commit message
270274
271- As you craft each patch you intend to submit to the Perl core, it's
272- important to write a good commit message. This is especially important
273- if your submission will consist of a series of commits.
275+ A commit message needs to answer these questions about the commit:
276+ "Who", "When", "What", "Where", "Why", and "How".
274277
275- The first line of the commit message should be a short description
276- without a period. It should be no longer than the subject line of an
277- email, 50 characters being a good rule of thumb .
278+ git automatically inserts the "Who" (you), and "When" (now), so you
279+ don't generally have to worry about these. But you definitely need to
280+ answer the other four .
278281
279- A lot of Git tools (Gitweb, GitHub, git log --pretty=oneline, ...) will
280- only display the first line (cut off at 50 characters) when presenting
281- commit summaries.
282+ A commit message has two parts: a title and a body. In rare instances,
283+ the body can be omitted if the title adequately describes the change.
284+ In such cases, you can use a git shortcut to create the commit:
285+
286+ % git -a -m'perlhack: Fix spelling error'
287+
288+ This keeps git from opening an editor in which you are to compose your
289+ message, saving you key strokes.
290+
291+ In this case, the title answers "What" (spelling error) and "Where"
292+ (pod/perlhacktips.pod). It omits "Why", because it correctly assumes
293+ that the project's policy is that errors like this are always a bad
294+ thing that should be fixed. And it omits "How", because that answer is
295+ obvious in this case.
296+
297+ The title is extremely important. It will be read over and over again
298+ far into the future; much more often than the body. It is unfair to the
299+ future maintainers of Perl to skimp on its creation now.
300+
301+ And the title has to be short, about 50 characters max, like the
302+ Subject: line of an email. Some tools will refuse to accept a longer
303+ title, and some will just truncate its display at or about the 50th
304+ character.
305+
306+ A title needs to convey enough information in the limited space allowed
307+ so that someone doing "git log" can immediately decide if the body of
308+ the commit message pertains to what they currently need, or if they can
309+ skip to the next commit without delving further.
310+
311+ That means it needs to answer "What" and "Where" at a minimum, and a
312+ hint of "Why" if there is room. "How" can generally be deferred to the
313+ message body.
314+
315+ "What" needs to have enough detail to be helpful, but not so much as to
316+ provide non-meaningful details. In fixing a spelling error, for
317+ example, people aren't very likely to want to know which word was
318+ misspelled. And giving that information to them can distract them from
319+ concentrating from their real purpose. Do a "git log" yourself. It
320+ should mostly have good examples of titles that answer this question,
321+ and the occasional one that leaves you wishing it had more.
322+
323+ "Where" can vary greatly in its form. In some cases it would refer to a
324+ subsystem, like "regex" or "mro" (method resolution order). In some
325+ cases, to a particular function:
326+
327+ % git -a -m'Use getentropy() for seeding PRNG in Perl_seed()'
328+
329+ In a few cases, a file:
330+
331+ % git -a -m'embed.fnc: Add pointer assertions for refcounted functions'
332+
333+ Sometimes, a module:
334+
335+ % git -a -m'Devel::PPPort: Add support for utf8_to_uv'
336+
337+ And rarely, entirely omitted:
338+
339+ % git -a -m'Add feature "class"'
340+
341+ Terseness is helpful in commit titles. This is not only because of the
342+ 50 character limitation, but to bias you to not add unnecessary detail,
343+ thus making it faster for people skimming "git log" in the future. The
344+ style "Where: rest-of-title" tends to use the fewest characters for the
345+ "Where" answer, leaving more for the "What". Sometimes you will have to
346+ get creative to make things fit. For example, 'Devel::' in the example
347+ above could have been omitted if the message exceeded the character
348+ limit. You may have to spend a bit of time to rewrite the title more
349+ concisely. Abbreviations are acceptable, when needed. But keep in mind
350+ that this will be read by people whose first language is not English.
351+
352+ The body of the commit message fills in the details, in plain English.
353+ In order to get the commit actually merged, it needs to persuade someone
354+ with the authority to do that that this change is desirable enough to
355+ outweigh considerations of potential harm. It should not contain text
356+ tangential to the main point.
357+
358+ No convincing is generally necessary (and hence nothing beyond the title
359+ need be included) for cases like this:
360+
361+ % git -a -m'"Where": Add/clarify comments"
362+ % git -a -m'"Where": Use more mnemonic variable name"
363+ % git -a -m'"Where": Move ARGS_ASSERT to top of function"
364+
365+ (This last is because anyone who can merge commits would know that such
366+ macros are best placed at the top of functions, and that many weren't,
367+ simply because of C89 compiler limitations that were lifted by our move
368+ to C99.)
282369
283370The commit message should include a description of the problem that the
284371patch corrects or new functionality that the patch adds.
@@ -292,7 +379,7 @@ to Perl.
292379
293380=item * Why
294381
295- Your commit message should describe why the change you are making is
382+ The message body should describe why the change you are making is
296383important. When someone looks at your change in six months or six
297384years, your intent should be clear.
298385
@@ -303,18 +390,23 @@ that.
303390
304391=item * What
305392
306- Your commit message should describe what part of the Perl core you're
307- changing and what you expect your patch to do.
393+ The message body should amplify what's in the title to describe what
394+ part of the Perl core you're changing and what you expect your patch to
395+ do.
308396
309397=item * How
310398
311399While it's not necessary for documentation changes, new tests or
312- trivial patches, it's often worth explaining how your change works.
400+ trivial patches, it's usually worth explaining how your change works.
313401Even if it's clear to you today, it may not be clear to a porter next
314402month or next year.
315403
316404=back
317405
406+ The body is the place for explaining why this particular implementation
407+ was chosen over alternatives that were considered. If you claim
408+ performance gains, this would be the place to add supporting benchmarks.
409+
318410A commit message isn't intended to take the place of comments in your
319411code. Commit messages should describe the change you made, while code
320412comments should describe the current state of the code.
0 commit comments