1.目标
重新了解一段程式码更动的脉络很浪费脑力。虽然这件事情没办法完全避免,但是我们可以尽量降低这件事情的複杂度。Commit messages 正可以做到这点,而我们可以从 commit message 看出一个开发者是不是一位好的合作对象。统一格式后,将可以通过脚本自动产生 CHANGELOG.md统一格式后,将可以通过 git bisect 忽略不重要的提交,如排版格式化2.Git commit message 的规则
用一行空白行分隔标题与内容限制标题最多只有 50 字元标题开头要大写标题不以句点结尾标题不需要礼貌,要直接有力以近乎命令式的祈使句来撰写标题,举例:把门关起来、把垃圾拿走内文每行最多 100 字用内文解释 what 以及 why vs. how2-1 Commit Message 的格式
<type>(<scope>): <subject><BLANK LINE><body><BLANK LINE><footer>
commit message 的任何一行不能超过 100 个字元! 这样可以使得 commit message 更容易在 github 以及各种 git 工具中阅读。
commit message 由header、 body 和 footer 组成,由空白行分隔。
2-2 Commit Message 格式的定义
header
Message header 是一行简洁的描述,其中包含 type、scope 和 subject。代表 commit 的类别:
feat (功能特点)
fix (修 bug)
docs (文件)
style (格式排版, 缺少分号…)
refactor (重构)
test (当补上缺少的测试时)
chore (维护)
scope 代表 commit 影响的範围,例如资料库、控制层、模板层等等,视专案不同而不同。 例如 $location, $browser, $compile, $rootScope, ngHref, ngClick, ngView, etc...如果没有更合适的範围,您可以使用 *****为可选栏位。代表此 commit 的简短描述
使用命令式, 使用现在式,例如: “change” 不要用 “changed” 也不要用 “changes”
text 第一个字母不要大写
末尾没有点 (.) 不要加句号
为必要栏位。
body
如同 使用命令式、现在式,例如:“change” 不是“changed”也不是“changes”
包括改变的动机和与以前行为的对比
更多说明:
http://365git.tumblr.com/post/3308646748/writing-git-commit-messages
http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
footer
Message header 是一行简洁的描述,其中包含 type、scope 和 subject。Breaking changes
所有重大更改都必须在 footer 中的 "BREAKING CHANGE" 区块里提及,该区块应以 BREAKING CHANGE 开头:空格或两个换行符。 然后,commit message 的其余部分是对更改、理由和迁移说明的描述。BREAKING CHANGE: isolate scope bindings definition has changed andthe inject option for the directive controller injection was removed. To migrate the code follow the example below: Before: scope: { myAttr: 'attribute', myBind: 'bind', myExpression: 'expression', myEval: 'evaluate', myAccessor: 'accessor' } After: scope: { myAttr: '@', myBind: '@', myExpression: '&', // myEval - usually not useful, but in cases where the expression is assignable, you can use '=' myAccessor: '=' // in directive's template change myAccessor() to myAccessor }The removed `inject` wasn't generaly useful for directives so there should be no code using it.
Referencing issues
已关闭的错误应列在页脚的单独行中,并以“Closes”关键字为前缀,如下所示:Closes #234
或在多个问题的情况下:Closes #123, #245, #992
还原 Revert
如果 commit 一个先前 commit 的还原 ,则其标头应以 **revert:**
开头,后面跟随着 reverted commit 的标头。
在 body 中它应该说:This reverts commit <hash>.
,其中 hash 是要恢复的提交的 SHA。
3.其他应用
3-1 自动产生 CHANGELOG.md
我们在变更日誌中使用这三个部分: new features, bug fixes, breaking changes.
此列表可以在发布时由脚本生成。以及相关提交的链接。
当然,您可以在实际发布之前编辑此更改日誌,但它可以生成骨架。
自上次发布以来的所有主题列表(提交消息中的第一行):
>> git log <last tag> HEAD --pretty=format:%s
此版本中的新功能
>> git log <last release> HEAD --grep feature
3-2 识别不重要的提交
这些是格式更改 (adding/removing spaces/empty lines, indentation), missing semi colons, comments.
所以当你在寻找一些改变时,你可以忽略这些提交 - 此提交中没有逻辑更改。
一分为二一目了然, 您可以通过以下方式忽略这些:
>> git bisect skip $(git rev-list --grep irrelevant <good place> HEAD)
3-3 浏览历史纪录时提供更多资讯
这将添加一种“context”资讯。
看看这些资讯 (取自最近几个 Angular 的提交):
Fix small typo in docs widget (tutorial instructions)Fix test for scenario.Application - should remove old iframedocs - various doc fixesdocs - stripping extra new linesReplaced double line break with single when text is fetched from GoogleAdded support for properties in documentation所有这些资讯都试图指出它更改了哪里。 但是他们缺少了规範...
看看这些资讯:
fix comment strippingfixing broken linksBit of refactoringCheck whether links do exist and throw exceptionFix sitemap include (to work on case sensitive linux)你能猜出里面是什么吗?这些消息错过了地方规範...These messages miss place specification...
所以也许像代码的一部分:docs, docs-parser, compiler, scenario-runner, …
我知道,您可以通过检查哪些文件已更改来找到此资讯,但这很慢。 在查看 git 历史纪录时,我可以看到我们所有人都试图指出癥结点,但却缺少了规範。
4. 範例
4-1 範例 feat
feat($browser): onUrlChange event (popstate/hashchange/polling)Added new event to $browser:- forward popstate event if available- forward hashchange event if popstate not available- do polling when neither popstate nor hashchange availableBreaks $browser.onHashChange, which was removed (use onUrlChange instead)
4-2 範例 fix
fix($compile): couple of unit tests for IE9Older IEs serialize html uppercased, but IE9 does not...Would be better to expect case insensitive, unfortunately jasmine doesnot allow to user regexps for throw expectations.Closes #392Breaks foo.bar api, foo.baz should be used instead
4-3 範例 feat
feat(directive): ng:disabled, ng:checked, ng:multiple, ng:readonly, ng:selectedNew directives for proper binding these attributes in older browsers (IE).Added coresponding description, live examples and e2e tests.Closes #351
4-4 範例 style
style($location): add couple of missing semi colons
4-5 範例 docs
docs(guide): updated fixed docs from Google DocsCouple of typos fixed:- indentation- batchLogbatchLog -> batchLog- start periodic checking- missing brace
4-6 範例 BREAKING CHANGE
feat($compile): simplify isolate scope bindingsChanged the isolate scope binding options to: - @attr - attribute binding (including interpolation) - =model - by-directional model binding - &expr - expression execution bindingThis change simplifies the terminology as well asnumber of choices available to the developer. Italso supports local name aliasing from the parent.BREAKING CHANGE: isolate scope bindings definition has changed andthe inject option for the directive controller injection was removed.To migrate the code follow the example below:Before:scope: { myAttr: 'attribute', myBind: 'bind', myExpression: 'expression', myEval: 'evaluate', myAccessor: 'accessor'}After:scope: { myAttr: '@', myBind: '@', myExpression: '&', // myEval - usually not useful, but in cases where the expression is assignable, you can use '=' myAccessor: '=' // in directive's template change myAccessor() to myAccessor}The removed `inject` wasn't generaly useful for directives so there should be no code using it.
参考:
参照国外 AngularJS 团队的规範: AngularJS Git Commit Message ConventionsHow to Write a Git Commit Message, 31 Aug 2014, By Chris Beams, https://chris.beams.io/posts/git-commit/Git Commit Message 这样写会更好,替专案引入规範与範例参考:参照国外 AngularJS 团队的规範: AngularJS Git Commit Message ConventionsHow to Write a Git Commit Message, 31 Aug 2014, By Chris Beams, https://chris.beams.io/posts/git-commit/Git Commit Message 这样写会更好,替专案引入规範与範例