自定义 Git 提交消息模板

Custom Git Commit Message Template

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

我想要这样的东西:

# Short (50 chars or fewer) summary of changes

# More detailed explanatory text

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

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

创建 ~/.git-commit-message 包含以下内容的文件:

# Short (50 chars or fewer) summary of changes

# More detailed explanatory text

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

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

您需要设置 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 默认使用它可以帮助增加定期遵守该政策的机会。

谢谢!