Skip to content
Laviyx Learn

Try

Git and GitHub course menu

git log and git show: How to View Commit History

Read Git history with git log, use --oneline, --graph, -n, --author, --grep and path filters, inspect a commit with git show, and understand commit IDs and HEAD.

Beginner7 min readUpdated
On this page

Git keeps every commit, so the history answers questions such as "when did this change?" and "who wrote this?". Here we use a small repository with four commits.

git log#

Terminal
git log
Output
commit ba5856ee63f34eceecaddd4d37d07b5ede586db8
Author: Ravi Kumar <ravi@example.com>
Date:   Thu Nov 5 09:15:00 2026 +0530

    Add rent reminder

commit 3b9e2f31489cae285a4944c60ad8dfd041f3f6d3
Author: Asha Rao <asha@example.com>
Date:   Thu Nov 5 09:10:00 2026 +0530

    Add README

commit 0a307519446a264c8acf34d683be0877384acb85
Author: Asha Rao <asha@example.com>
Date:   Thu Nov 5 09:05:00 2026 +0530

    Add reminder to call the bank

commit 3b1b8d5afc4ced2f188414298d045b62b8f5c2bf
Author: Asha Rao <asha@example.com>
Date:   Thu Nov 5 09:00:00 2026 +0530

    Add shopping note

For each commit you see its full ID, author, date and message, newest first. If the output is long, Git shows it in a pager: press Space to scroll and q to quit.

The 40-character ID is a SHA-1 hash calculated from the commit's content, parents, author and time. Change anything and the ID changes. The first seven or so characters are normally enough to identify a commit.

HEAD (-> main) in the log means you are on the main branch, and main points to this commit. Think of HEAD as "where I am now".

You can count backwards from it: HEAD~1 is the previous commit, HEAD~2 is two commits back.

Shorter views#

Terminal
git log --oneline
Output
ba5856e Add rent reminder
3b9e2f3 Add README
0a30751 Add reminder to call the bank
3b1b8d5 Add shopping note

Limit the number of commits with -n:

Terminal
git log --oneline -n 2
Output
ba5856e Add rent reminder
3b9e2f3 Add README

Filtering#

By author:

Terminal
git log --oneline --author="Ravi"
Output
ba5856e Add rent reminder

By words in the message:

Terminal
git log --oneline --grep="bank"
Output
0a30751 Add reminder to call the bank

Commits that changed one file:

Terminal
git log --oneline -- README.md
Output
3b9e2f3 Add README

Other useful filters are --since="2 weeks ago" and --until="2026-01-01".

Which files changed#

--stat adds a summary of the files changed in each commit:

Terminal
git log --stat -n 1
Output
commit ba5856ee63f34eceecaddd4d37d07b5ede586db8
Author: Ravi Kumar <ravi@example.com>
Date:   Thu Nov 5 09:15:00 2026 +0530

    Add rent reminder

 notes.txt | 1 +
 1 file changed, 1 insertion(+)

Inspect one commit#

git show displays a commit and exactly what it changed:

Terminal
git show HEAD~1
Output
commit 3b9e2f31489cae285a4944c60ad8dfd041f3f6d3
Author: Asha Rao <asha@example.com>
Date:   Thu Nov 5 09:10:00 2026 +0530

    Add README

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..17e0f0d
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+# Notes

The lines starting with + were added. You will learn to read this format in the next lesson.

To see a file as it was in an older commit, without changing anything:

Terminal
git show HEAD~2:notes.txt
Output
Buy milk
Call the bank

The graph view#

Once you have branches, this view shows how they fit together:

Terminal
git log --oneline --graph --all

It is so useful that many developers save it as an alias:

Terminal
git config --global alias.lg "log --oneline --graph --all"
git lg

Common mistakes#

Practice#

Practice exercise

In this repository, print the commits written by Asha in one-line format, then print only the first line of notes.txt as it was two commits before HEAD.

Show hint

git show HEAD~2:notes.txt prints the file. Pipe it to head -n 1.

Show solution
Terminal
git log --oneline --author="Asha"
git show HEAD~2:notes.txt | head -n 1
Output
3b9e2f3 Add README
0a30751 Add reminder to call the bank
3b1b8d5 Add shopping note
Buy milk

Key takeaway#

Next: Seeing Changes with git diff.

Finished this lesson?