|
| 1 | + |
| 2 | +# [gitmessage]提交模板 |
| 3 | + |
| 4 | +## 默认模板 |
| 5 | + |
| 6 | +在提交时打开编译器,默认会出现一段模板信息,提示你编辑提交信息,同时会提示当前修改的文件 |
| 7 | + |
| 8 | + $ git commit |
| 9 | + |
| 10 | + # Please enter the commit message for your changes. Lines starting |
| 11 | + # with '#' will be ignored, and an empty message aborts the commit. |
| 12 | + # On branch master |
| 13 | + # Your branch is ahead of 'origin/master' by 1 commit. |
| 14 | + # (use "git push" to publish your local commits) |
| 15 | + # |
| 16 | + # Changes to be committed: |
| 17 | + # modified: ... |
| 18 | + # deleted: ... |
| 19 | + # |
| 20 | + |
| 21 | +## 自定义模板 |
| 22 | + |
| 23 | +可以自己编辑一个模板文件,比如新建`~/.gitmessage`,编辑一段关于提交规范的注释 |
| 24 | + |
| 25 | + $ vim ~/.gitmessage |
| 26 | + |
| 27 | + # head: <type>(<scope>): <subject> |
| 28 | + # - type: feat, fix, docs, style, refactor, test, chore |
| 29 | + # - scope: can be empty (eg. if the change is a global or difficult to assign to a single component) |
| 30 | + # - subject: start with verb (such as 'change'), 50-character line |
| 31 | + # |
| 32 | + # body: 72-character wrapped. This should answer: |
| 33 | + # * Why was this change necessary? |
| 34 | + # * How does it address the problem? |
| 35 | + # * Are there any side effects? |
| 36 | + # |
| 37 | + # footer: |
| 38 | + # - Include a link to the ticket, if any. |
| 39 | + # - BREAKING CHANGE |
| 40 | + # |
| 41 | + |
| 42 | +修改全局配置文件`~/.gitconfig`,添加 |
| 43 | + |
| 44 | + [commit] |
| 45 | + template = ~/.gitmessage |
| 46 | + |
| 47 | +再次提交时显示的模板如下 |
| 48 | + |
| 49 | + # head: <type>(<scope>): <subject> |
| 50 | + # - type: feat, fix, docs, style, refactor, test, chore |
| 51 | + # - scope: can be empty (eg. if the change is a global or difficult to assign to a single component) |
| 52 | + # - subject: start with verb (such as 'change'), 50-character line |
| 53 | + # |
| 54 | + # body: 72-character wrapped. This should answer: |
| 55 | + # * Why was this change necessary? |
| 56 | + # * How does it address the problem? |
| 57 | + # * Are there any side effects? |
| 58 | + # |
| 59 | + # footer: |
| 60 | + # - Include a link to the ticket, if any. |
| 61 | + # - BREAKING CHANGE |
| 62 | + # |
| 63 | + |
| 64 | + # Please enter the commit message for your changes. Lines starting |
| 65 | + # with '#' will be ignored, and an empty message aborts the commit. |
| 66 | + # On branch master |
| 67 | + # Your branch is ahead of 'all/master' by 2 commits. |
| 68 | + # (use "git push" to publish your local commits) |
| 69 | + # |
| 70 | + # Changes to be committed: |
| 71 | + # new file: .gitignore |
| 72 | + # |
| 73 | + # Untracked files: |
| 74 | + # package.json |
| 75 | + # |
| 76 | + |
| 77 | +## 文件解析 |
| 78 | + |
| 79 | +在仓库内的`.git/COMMIT_EDITMSG`文件中保存了最近一次提交的日志(包括模板信息) |
| 80 | + |
| 81 | +## 相关阅读 |
| 82 | + |
| 83 | +* [优雅的提交你的 Git Commit Message](https://zhuanlan.zhihu.com/p/34223150) |
0 commit comments