Git Commit Messages: 50/72 Formatting

后端 未结 5 1378
不知归路
不知归路 2020-11-29 14:10

Tim Pope argues for a particular Git commit message style in his blog post: http://www.tpope.net/node/106.

Here is a quick summary of what he recommends:

    <
5条回答
  •  鱼传尺愫
    2020-11-29 14:51

    Regarding the “summary” line (the 50 in your formula), the Linux kernel documentation has this to say:

    For these reasons, the "summary" must be no more than 70-75
    characters, and it must describe both what the patch changes, as well
    as why the patch might be necessary.  It is challenging to be both
    succinct and descriptive, but that is what a well-written summary
    should do.
    

    That said, it seems like kernel maintainers do indeed try to keep things around 50. Here’s a histogram of the lengths of the summary lines in the git log for the kernel:

    (view full-sized)

    There is a smattering of commits that have summary lines that are longer (some much longer) than this plot can hold without making the interesting part look like one single line. (There’s probably some fancy statistical technique for incorporating that data here but oh well… :-)

    If you want to see the raw lengths:

    cd /path/to/repo
    git shortlog  | grep -e '^      ' | sed 's/[[:space:]]\+\(.*\)$/\1/' | awk '{print length($0)}'
    

    or a text-based histogram:

    cd /path/to/repo
    git shortlog  | grep -e '^      ' | sed 's/[[:space:]]\+\(.*\)$/\1/' | awk '{lens[length($0)]++;} END {for (len in lens) print len, lens[len] }' | sort -n
    

提交回复
热议问题