经历过团队合作的人们往往能够体会到一个好的git log记录是多少重要,一个好的git commit message是多么地让人赏心悦目,节省不少时间,能够更好地搞懂来龙去脉。
《Git Pro》一书给了这样一个模板:
Summarize changes in around 50 characters or less
More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as the
subject of the commit and the rest of the text as the body. The
blank line separating the summary from the body is critical (unless
you omit the body entirely); various tools like `log`, `shortlog`
and `rebase` can get confused if you run the two together.
Explain the problem that this commit is solving. Focus on why you
are making this change as opposed to how (the code explains that).
Are there side effects or other unintuitive consequences of this
change? Here's the place to explain them.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet, preceded
by a single space, with blank lines in between, but conventions
vary here
If you use an issue tracker, put references to them at the bottom,
like this:
Resolves: #123
See also: #456, #789
注意在body中主要表现的是what和why,至于how读者大可以去自己diff看。
还有另一种模板:
# Hey there o/!
#
# We just wanted to let you know that we care a great deal about
# making our git history clean, maintainable and easy to access for
# all our contributors. Commit messages are very important to us,
# which is why we have a strict commit message policy in place.
# Please use the following guidelines to format all your commit
# messages:
#
# <type>(<scope>): <subject>
# <BLANK LINE>
# <body>
# <BLANK LINE>
# <footer>
#
# Please note that:
# - The HEADER is a single line of max. 50 characters that
# contains a succinct description of the change. It contains a
# type, an optional scope, and a subject
# + <type> describes the kind of change that this commit is
# providing. Allowed types are:
# * feat (feature)
# * fix (bug fix)
# * docs (documentation)
# * style (formatting, missing semicolons, …)
# * refactor
# * test (when adding missing tests)
# * chore (maintain)
# + <scope> can be anything specifying the place of the commit
# change
# + <subject> is a very short description of the change, in
# the following format:
# * imperative, present tense: “change” not
# “changed”/“changes”
# * no capitalised first letter
# * no dot (.) at the end
# - The BODY should include the motivation for the change and
# contrast this with previous behavior and must be phrased in
# imperative present tense
# - The FOOTER should contain any information about Breaking
# Changes and is also the place to reference GitHub issues that
# this commit closes
#
# Thank you <3
至于使用哪一种,一个团队保持统一就好。
参考:
https://www.conventionalcommits.org/en/v1.0.0/
https://chris.beams.io/posts/git-commit/
https://backlog.com/blog/git-commit-messages-bold-daring/