Can I use a scripted commit template for git?

前端 未结 2 1720
生来不讨喜
生来不讨喜 2021-01-31 08:15

We are working on tickets, and when we use the ticket number in the git commit message on the first line, then the ticket is updated with the commit message.

To make thi

2条回答
  •  生来不讨喜
    2021-01-31 09:11

    Looks like you should be able to do this by using the .git/hooks/pre-commit-msg

    An simple example of this would be:

    #!/bin/sh
    # $1 contains the file with the commit msg we're about to edit.
    # We'll just completely clobber it for this example.
    echo "Hello" > "$1"
    

    This would make your commit begin with "Hello". Obviously, since it's a script you can work some magic here to fill out your ticket number and any other information. There should be a pre-commit-msg.sample in the .git/hooks/ directory telling you which args the script receives if you need anything else.

提交回复
热议问题