Often during a commit ($ git -commit -m ""
), I wish to read my last comment to remember what progress I have made. Is there an easy way to directly access the last commit message through command-line? (I'm using Windows.)

- 57,944
- 17
- 167
- 143

- 8,320
- 9
- 40
- 50
-
6If it is a regular action, make an `alias` (e.g. `wherewasi` ;-) for your chosen solution / command line. You could include the branch info as well. – Philip Oakley Sep 03 '11 at 15:16
12 Answers
git show
is the fastest to type, but shows you the diff as well.
git log -1
is fast and simple.
git log -1 --pretty=%B
if you need just the commit message and nothing else.

- 755,051
- 104
- 632
- 656
-
(on ubuntu) the line is truncated if it does not fit in the shell. Any idea how to make it print a multi-line message? – Juh_ Nov 14 '14 at 09:14
-
3the %B format was what I needed to not have the commit message indented. And yes, @Juh_, even though git gui doesn't linewrap for you, it's a good idea to use 80column text in commit messages, not line-per-paragraph. – Peter Cordes Dec 13 '14 at 01:06
-
6@Juh_ You can show the whole message by using `git log -1 --pretty=%B | cat`, but as Peter said, you should try to keep it to 80 characters. – Ruckus T-Boom Jan 20 '15 at 22:32
-
5@Juh_ this is a bit too late but if you want the commit message to line-wrap, just pipe the output to `cat` i.e: `git log -1 --pretty= | cat` – kosgeinsky Jul 27 '15 at 14:51
-
13Someone looking for more information on the percent-placeholders, see: https://www.kernel.org/pub/software/scm/git/docs/git-log.html#_pretty_formats (scroll down to ``format:
``). – imme Jul 31 '15 at 15:36 -
If a commit message is needed of a PR, build servers normally create a new branch to merge your feature branch and development. You will get a hash as a commit message. If you want to get earlier commits, use 2 as parameter. `git log -2 --pretty=%B` – MQoder Jan 07 '19 at 15:59
-
If I do `MESSAGE=$(git log -1 --pretty=%B); echo $MESSAGE`, I get strange results: Lines that start with the star character `*` in the Git commit message are replaced with `ls` output of file names. Why is this? How to prevent it? – Mr-IDE Aug 08 '19 at 22:18
-
16If you add the `format:` prefix to the `%B` as suggested in the man docs, it wont show extra blank lines at the end of the output: `git log -1 --pretty=format:%B` – Mariano Ruiz Jan 03 '20 at 13:52
Generally:
git log -n
will show you the last n
commit messages
More elegantly - if you want a quick overview of your commits
git log --oneline -n
This will show just the first line of the last n
commit messages.
You can save this as a git alias or a shell alias with a shorter command. I've got it in my shell as glog
, for example, and I can see my last 10 commit messages with glog -10
.
You can use
git show -s --format=%s
Here --format
enables various printing options, see documentation here. Specifically, %s
means 'subject'. In addition, -s
stands for --no-patch
, which suppresses the diff content.
I often use
git show -s --format='%h %s'
where %h
denotes a short hash of the commit
Another way is
git show-branch --no-name HEAD
It seems to run faster than the other way.
I actually wrote a small tool to see the status of all my repos, including the edit status, the relation to remote branch, etc. It also batch executes commands from any working directory.
You can find it on github.

- 19,875
- 27
- 98
- 134
-
3IMO this is better than the accepted answer for multiple commits. It does not produce unnecessary linebreaks for me. Multiple commits (i.e. past 5) can be shown by including -5, i.e. `git show -s --format=%s -5` – Sigmatics Mar 23 '20 at 16:11
-
It does not show the line break in commit, so it is good for the people want the whole commit in one line. – Ding-Yi Chen Mar 03 '22 at 00:01
git log -1
will display the latest commit message or git log -1 --oneline
if you only want the sha1 and associated commit message to be displayed.

- 69,011
- 20
- 139
- 164
git log -1 branch_name
will show you the last message from the specified branch (i.e. not necessarily the branch you're currently on).

- 4,226
- 2
- 40
- 69
If you want to see just the subject (first line) of the commit message:
git log -1 --format=%s
This was not previously documented in any answer. Alternatively, the approach by nos also shows it.
Reference:

- 57,944
- 17
- 167
- 143
For something a little more readable, run this command once:
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
so that when you then run:
git lg
you get a nice readout. To show only the last line:
git lg -1
Solution found here

- 3,152
- 5
- 32
- 49
To start with git log -1 --pretty='%s'
But the below one covers all the cases,
git log --pretty='format:%Creset%s' --no-merges -1
- No unwanted white spaces
- Discards merge commits
- No commit id, date, Displays only the messages.
Paste & see for yourself

- 12,775
- 6
- 58
- 84
This command will get you the last commit message:
git log -1 --oneline --format=%s | sed 's/^.*: //'
outputs something similar to:
Create FUNDING.yml
You can change the -1 to any negative number to increase the range of commit messages retrieved

- 5,827
- 2
- 19
- 22
You can display the previous/current commit message in the commit message as a comment.
touch .git/hooks/prepare-commit-msg
chmod +x .git/hooks/prepare-commit-msg
$EDITOR .git/hooks/prepare-commit-msg
Content:
#!/bin/sh
COMMIT_MSG_FILE=$1
printf "# Previous commit message:\n" >> $COMMIT_MSG_FILE
printf "#\n" >> $COMMIT_MSG_FILE
git log -1 --pretty=format:%B | sed -e 's/^/# /' >> $COMMIT_MSG_FILE
If this is the last commit message (HEAD
):
Simplify further
Simplicity always wins!
Then this is what the commit message will look like in your editor:
<cursor>
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch strs
# Changes to be committed:
# new file: test.txt
#
# Previous commit message:
#
# Simplify further
#
# Simplicity always wins!
But this is pretty flawed. git commit --amend
will display the same commit message:
Simplify further
Simplicity always wins!
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date: Thu Mar 2 20:30:46 2023 +0100
#
# On branch strs
# Changes to be committed:
# modified: git-branchless-lib/src/git/object.rs
# new file: test.txt
#
# Previous commit message:
#
# Simplify further
#
# Simplicity always wins!
But this might be okay for simple use-cases.

- 2,179
- 1
- 17
- 39
I just found out a workaround with shell by retrieving the previous command.
Press Ctrl-R to bring up reverse search command:
reverse-i-search
Then start typing git commit -m, this will add this as search command, and this brings the previous git commit with its message:
reverse-i-search`git commit -m`: git commit -m "message"
Enter. That's it!
(tested in Ubuntu shell)

- 71
- 6