How to Show Current Git Commit's Message?

Display current/latest git commit message

The following command will show you full commit details (including the message) for the latest/current commit:

git log -1

The "-1" in git log -n command refers to the latest commit.

You may achieve the same with the git show command in the following way:

git show -s

The -s flag (or --no-patch) is optional. However, it is specified here to suppress the diff output — which is shown by the git show command by default in addition to the full commit details.

Both these commands will produce an output like the following:

commit 80c6ed6965e38cac149b3ee0a677358406955ef0 (HEAD -> main, origin/main, origin/HEAD)
Author: Designcise <[email protected]>
Date:   Wed Dec 29 16:24:50 2021 +0100

    This is an example commit message

You can use the --oneline option with either of the commands to display a compact summary of the latest commit (including the commit message):

git log -1 --oneline
git show -s --oneline

This would produce an output like the following:

80c6ed6 (HEAD -> main, origin/main, origin/HEAD) This is an example commit message

Alternatively, to only output the latest commit message, you can specify the --format=%s option:

git log -1 --format=%s
git show -s --format=%s

This would result in an output only showing the commit message, for example, like the following:

This is an example commit message

The %s in --format=<format> option refers to the "subject" line of the commit output.

You may additionally add the %h format modifier to also output the short hash of the commit (or %H for the full hash), for example, like so:

git log -1 --format='%h %s'
git show -s --format='%h %s'

This would result in an output like the following:

80c6ed6 This is an example commit message

Hope you found this post useful. It was published . Please show your love and support by sharing this post.