自定义Git提交消息模板

时间:2015-08-07 08:55:34

标签: git git-commit

如何制作自定义提交消息模板?

我希望有类似的东西:

# Short (50 chars or fewer) summary of changes

# More detailed explanatory text

2 个答案:

答案 0 :(得分:4)

将以下内容添加到~/.gitconfig

[commit]
  template = ~/.git-commit-message

enter image description here

使用以下内容创建~/.git-commit-message文件:

# Short (50 chars or fewer) summary of changes

# More detailed explanatory text

参考。 http://git-scm.com/docs/git-config

中的commit.template

答案 1 :(得分:2)

创建自定义提交模板的价值在于,您可以在创建提交消息时使用它来提醒自己(或其他人)正确的格式和样式。

您需要设置3个简单的步骤,以便在您(或其他人)使用以下方法提交时可以遵循相同的格式:git commit

1)您需要使用git命令添加编辑器.exe文件

git config --global core.editor "your editor full path" (ex: C:/Windows/notepad.exe)

注意:以管理员身份运行git

2)现在,将模板文本添加到一个文件中,并使用一些名称.txt(例如:commit_template.txt)保存在您首选的位置(您可以将其保存在计算机中的任何位置)

您的自定义提交消息可能像

Subject line (try to keep under 50 characters)

Multi-line description of commit,

feel free to be detailed.

[Ticket: X]

Resolves : #121, #12

3)通过添加以下命令,将模板设置为默认模板和自定义提交模板:

git config --global commit.template "path of txt file" (ex: D:/My Commit Template/commit_template.txt)

如果您的团队具有提交消息策略,那么在系统上放置该策略的模板并将Git配置为默认使用它可以帮助增加定期遵循该策略的机会。

谢谢!

相关问题