git: Show index diff in commit message as comment

前端 未结 5 620
清歌不尽
清歌不尽 2021-01-30 05:10

When git commit open the message editor is shows a brief status, something like this:

# Please enter the commit message for your changes. Lines star         


        
5条回答
  •  感情败类
    2021-01-30 05:13

    I've put the following lines in .git/hooks/prepare-commit-msg to get a commented out diff:

    #!/bin/bash
    
    if [ "$2" == "" ] ; then
        git diff --staged -p --stat 2> /dev/null | awk '{ printf "#"; print}' >> "$1"  2>/dev/null
    fi
    

    This way you can not only comment out the diff, but also add more info (like the stat option does).

    Edit: Also git commit --verbose does not include the diff to the commit message this way would do without the #s.

提交回复
热议问题