git: Show index diff in commit message as comment

前端 未结 5 692
清歌不尽
清歌不尽 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:16

    Not enough reputation to post a reply to Alan's answer, but for Idan and anyone else I just tried it out and the diff lines in the commit message aren't explicitly commented out. However, they still don't show up in the final commit message, thank goodness.

    $ git commit --verbose

    In my editor:

    Feeling a bit pessimistic now.
    
    # 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 ..." to unstage)
    #
    #   modified:   README
    #
    diff --git a/README b/README
    index af5626b..c62237e 100644
    --- a/README
    +++ b/README
    @@ -1 +1 @@
    -Hello, world!
    +Goodbye, world!
    

    (note the lack of # preceding the diff lines)

    And then the actual commit message:

    $ git log -n 1
    commit ad21a2655ef6d8173c2df08dc9893055b26bc068
    Author: Tom Jakubowski 
    Date:   Thu Oct 27 19:12:54 2011 -0700
    
        Feeling a bit pessimistic now.
    

    Obviously, git show will still show the diff, but that's because it always does for commits. :)

提交回复
热议问题