How to specify a git commit message template for a repository in a file at a relative path to the repository?

后端 未结 4 1000
春和景丽
春和景丽 2020-12-08 06:23

Is there a way to specify a git commit.template that is relative to a repository?

For configuration an example is

$ git config commit.template $HOME/         


        
4条回答
  •  时光取名叫无心
    2020-12-08 06:47

    1. Create a file with your custom template inside your project directory.

    In this example in the .git/ folder of the project :

    $ cat << EOF > .git/.commit-msg-template
    > My custom template
    > # Comment in my template
    > EOF
    

    2. Edit the config file in the .git/ folder of your project to add the path to your custom template.

    • With git command :

      $ git config commit.template .git/.commit-msg-template
      
    • Or by adding in the config file the following lines :

      [commit]
        template = .git/.commit-msg-template
      

    Et voilà !

提交回复
热议问题