【问题标题】:How to remove git commit default template message?如何删除 git commit 默认模板消息?
【发布时间】:2019-09-21 21:26:12
【问题描述】:

如果我想创建一个自定义的 git commit 模板,我可以将模板的路径添加为:

[commit]
    template = ~/.gitmessage

但它一直附加在我的提交模板默认模板的底部:

# 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:   lib/test.rb
#

阅读configuration 他们还附加了默认模板。我知道它已被注释掉,但无论如何要删除它以便它只显示我的自定义模板?

【问题讨论】:

    标签: git git-commit git-config


    【解决方案1】:

    commit.status 设置为false

    git config commit.status false
    

    git -c commit.status=false commit
    

    【讨论】:

    • 它有效,谢谢。你能告诉我commit.status 是什么吗?在参考资料中找不到。
    • @DinkoPehar 这是一个预定义的配置参数。在git-scm.com/docs/git-config 上查看更多信息。当您有需求时,您可以先搜索文档,在那里您可能会找到解决方案。
    【解决方案2】:

    您可以使用 git hook 更改默认模板!

    默认情况下,您将拥有一个名为 prepare-commit-msg.sample 的 git 钩子,它让您对什么是可能的有所了解。您可以通过重命名文件来激活它:

     cp .git/hooks/prepare-commit-msg.sample .git/hooks/prepare-commit-msg
    

    现在,如果您提交,“默认模板”就消失了。请注意,git 挂钩存储在您的 .git/hooks 目录中,但您不能轻松地将它们推送到远程。 Git Book 中有很多关于此主题的信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-27
      • 2016-08-18
      • 2015-12-01
      • 2012-12-07
      • 1970-01-01
      • 2016-12-17
      相关资源
      最近更新 更多