git - 如何将项目特定信息添加到 Git 提交注释中?

标签 git version-control

使用 Git,如果您要提交,它会在提交消息下包含一个被注释掉的部分。这包含有关编写提交消息的说明以及正在更改的文件列表。像这样:

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:  important-file.txt 
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   some-other-thing.txt
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       untracked.txt

是否可以向该文件中添加更多 Material ?一个明确的用例是那些使用问题跟踪软件的人 Trac , Redmine等等是指定额外的语法元素。例如,Redmine 用户可以包含问题编号和一些特殊关键字以将问题标记为已解决:关键字是“refs”(和“references”)和“fixes”(或“closes”)——但我经常发现这很难记住关键字。

那么,如果可以在提交说明的底部附加一些项目特定的文本,那将会很方便。

是否有任何现有的方法可以做到这一点,或者我是否需要破解一个?作为附带问题,是否有任何其他 VCS(如 Mercurial)具有类似行为?

最佳答案

我使用了 commit.template(如 here 所述)。我本可以使用 prepare-commit-msg Hook ,但提交模板的工作稍微容易一些,而且我可以将提交模板保留在项目的版本控制中。

关于git - 如何将项目特定信息添加到 Git 提交注释中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3195303/

相关文章:

git: --prune-empty 使用 bfg 重复提交后

git - 弧形土地 "Not possible to fast-forward, aborting."

git - 跨多个 git 存储库组织 Kubernetes 对象的最佳实践?

svn - 在为工作项目考虑 git 与 svn 时,Mercurial 是两全其美的吗?

version-control - 分布式版本控制和访问控制

git - 同一台服务器上的生产、登台、开发网站和 git repos : how to setup GIT_DIR and GIT_WORK_TREE

git - "-0700"的结果中的 'git log' 部分意味着什么?

git - 如何在不复制子包代码的情况下将主要版本升级到 v2,并默认获取最新版本?

version-control - 分布式版本控制系统真的没有集中存储库吗?

svn - 从 Source Depot 迁移到 SVN