Get "PHP 8 in a Nuthshell" (Now comes with PHP 8.3)
Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

Attaching additional notes to a Git commit

When you commit a change in Git, you can add a message along with it. This message is essentially a note that you can add to the commit.

However, sometimes, you may want to add additional notes to the commit to add more context to it. For instance, recently, I deleted a file and committed the change with the message “deleted a file”. However, I wanted to add more context to the commit and add a note that the file was deleted because it was no longer needed.

Git Notes

Git allows you to add additional notes to an existing commit. You can do so by using the git notes command. For instance, you can add a note to a commit by specifying its ID like so.

$ git notes add -m "Deleted script.html because it was no longer needed" f0a40dfff6582a516dd47d4bde8831b45e4ec40d

Now, when you run the git log command, you’ll see the note added to the commit in addition to the commit message like so.

test git:(master) git log
commit f0a40dfff6582a516dd47d4bde8831b45e4ec40d (HEAD -> master)
Author: Amit Merchant <[email protected]>
Date:   Sun Jan 1 18:48:30 2023 +0530

    deleted a file

Notes:
    Deleted script.html because it was no longer needed

Here’s a screenshot of the same.

Git notes

Update a note

In any case, if you want to update the note, you can do so by adding the -f option to the git notes add command like so.

git notes add -f -m "Version 2 of the note" f0a40dfff6582a516dd47d4bde8831b45e4ec40d

Like this article? Consider leaving a

Tip

👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.

Comments?