1

Let's say I have git commit with git note:

commit 385f6c188a5b1cef25acb6412ba4acd7c25b0b9c (HEAD -> master)
Author: zuku
Date:   Tue Oct 8 14:14:31 2019 +0200

    Test commit

Notes:
    Test note

Now I want to add some more text to this note:

git notes append -m "Next line"
git notes append -m "Another line"

The problem is that every time git notes append adds also blank line:

commit 385f6c188a5b1cef25acb6412ba4acd7c25b0b9c (HEAD -> master)
Author: zuku
Date:   Tue Oct 8 14:14:31 2019 +0200

    Test commit

Notes:
    Test note

    Next line

    Another line

I do not see a purpose of that and really would like to avoid these empty lines. I know that I can use git notes edit and enter the text manually, but I need to do that from command line without using an editor. I didn't find any useful information in docs. Any ideas how to accomplish that? Thanks.

4

1 回答 1

3

使用这个小脚本

# 1 line script:
notes=$(git notes show HEAD); git notes add -f -m"${notes}<YOUR MESSAGE>"

解释

# Get the current note's message and store it in notes variable
# In this sample I'm using HEAD but you can use any commit you wish
notes=$(git notes show HEAD)

# Use the previous not and append the desired extra message to it
# Update the current message using the -f flag so it will overwrite the existing note
git notes add -f -m"${notes}<YOUR MESSAGE>"
于 2019-10-08T13:34:55.423 回答