代码之家  ›  专栏  ›  技术社区  ›  Tiina

提交[duplicate]时为git命令添加shell

git
  •  0
  • Tiina  · 技术社区  · 5 年前

    是否可以修改默认git commit消息的注释部分? 我想为我的用户添加更多的“上下文”信息。

    # Please enter the commit message for your changes.
    # (Comment lines starting with '#' will not be included)
    # Explicit paths specified without -i nor -o; assuming --only paths...
    # On branch master
    # Changes to be committed:
    #   (use "git reset HEAD <file>..." to unstage)
    #
    #       modified:   test.txt
    #
    
    0 回复  |  直到 6 年前
        1
  •  45
  •   doughgle    9 年前

    你可以用 git hooks 为了这个。在要提交更改的人显示提交消息之前,将运行prepare commit msg脚本。

    您可以在.git/hooks中找到一个prepare commit msg脚本示例。

    要编辑默认消息,请在.git/hooks文件夹中创建一个名为prepare commit msg的新文件。您可以使用以下脚本编辑提交消息:

    #!/bin/sh
    echo "#Some more info...." >> $1
    

    $1变量存储提交消息文件的文件路径。

        2
  •  73
  •   Jakub Narębski adamtaub    14 年前

    commit.template 配置变量,根据 git-config(1) 手册页:

    指定要用作 新提交消息的模板 . " ~/ “扩展到$HOME和” ~user/ “”到指定用户的主目录。

    您可以将其放入每个存储库( .git/config ),用户的( ~/.gitconfig )和系统( /etc/gitconfig )配置文件。

        3
  •  0
  •   Mat    5 年前

    这是一个 python git钩子 清除默认消息。挂钩名称: prepare-commit-msg .

    #!/usr/bin/env python
    import sys
    commit_msg_file_path = sys.argv[1]
    with open(commit_msg_file_path, 'a') as file:
        file.write('')
    

    您只需在 file.write() 方法。