gitgit-notes

`git notes append` creates additional blank line


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.


Solution

  • Use this tiny script

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

    Explanation

    # 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>"