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.
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#
git logcommit 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 noteFor 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#
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#
git log --onelineba5856e Add rent reminder
3b9e2f3 Add README
0a30751 Add reminder to call the bank
3b1b8d5 Add shopping noteLimit the number of commits with -n:
git log --oneline -n 2ba5856e Add rent reminder
3b9e2f3 Add READMEFiltering#
By author:
git log --oneline --author="Ravi"ba5856e Add rent reminderBy words in the message:
git log --oneline --grep="bank"0a30751 Add reminder to call the bankCommits that changed one file:
git log --oneline -- README.md3b9e2f3 Add READMEOther 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:
git log --stat -n 1commit 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:
git show HEAD~1commit 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 @@
+# NotesThe 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:
git show HEAD~2:notes.txtBuy milk
Call the bankThe graph view#
Once you have branches, this view shows how they fit together:
git log --oneline --graph --allIt is so useful that many developers save it as an alias:
git config --global alias.lg "log --oneline --graph --all"
git lgCommon 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
git log --oneline --author="Asha"
git show HEAD~2:notes.txt | head -n 13b9e2f3 Add README
0a30751 Add reminder to call the bank
3b1b8d5 Add shopping note
Buy milkKey takeaway#
Next: Seeing Changes with git diff.
Finished this lesson?