Viewing History
git log lists the commits in your history, newest first. On its own it's verbose, but its options turn it into a powerful search tool: one line per commit, a graph of branches, the files or lines each commit changed, and filters by author, date, message or file.
The full log
git log
commit beae5af33c0a9f731b34be23798823ecc2a69fad (HEAD -> main)
Author: Sam Rivera <sam@example.com>
Date: Mon Mar 2 10:31:00 2026 +0000
Add cheese to omelette
commit 9721f6b1ccc660e53c5a86bb95c868e86cc3917f
Merge: eec0917 eda718c
Author: Sam Rivera <sam@example.com>
Date: Mon Mar 2 10:24:00 2026 +0000
Merge branch 'soups'
commit eec091794d4e15fdad9fb0db3fa42ec8fc3f1384
Author: Alex Chen <alex@example.com>
Date: Mon Mar 2 10:17:00 2026 +0000
Add granola recipe and README
commit eda718cfeabdb51cdf841b1f506a45a36e3b9d04 (soups)
Author: Sam Rivera <sam@example.com>
Date: Mon Mar 2 09:56:00 2026 +0000
Add tomato soup
commit cfe25ef660e55597bb40cb8b3f19f8bed54b39c2
Author: Sam Rivera <sam@example.com>
Date: Mon Mar 2 09:35:00 2026 +0000
Add sugar to pancakes
commit 90c00895dd5f3596c58ac005e17872f41039efcb
Author: Sam Rivera <sam@example.com>
Date: Mon Mar 2 09:28:00 2026 +0000
Add omelette recipe
commit c4f5e477cc93474bd7d8597fe508a0ba50d132f6
Author: Sam Rivera <sam@example.com>
Date: Mon Mar 2 09:14:00 2026 +0000
Add pancake recipeEach entry shows the full hash, the author, the date and the message. The newest commit is at the top and is marked HEAD -> main: it's where you are. One commit is a merge, with two parents listed on its Merge: line — you'll create merges in lesson 24.
When the log is longer than your screen, Git shows it in a pager: scroll with the arrow keys or space bar, search with /, and press q to quit.
One line per commit
git log --oneline
beae5af (HEAD -> main) Add cheese to omelette 9721f6b Merge branch 'soups' eec0917 Add granola recipe and README eda718c (soups) Add tomato soup cfe25ef Add sugar to pancakes 90c0089 Add omelette recipe c4f5e47 Add pancake recipe
This is the form you'll use most. Limit the number of commits with -n, or just a number:
git log --oneline -3
beae5af (HEAD -> main) Add cheese to omelette 9721f6b Merge branch 'soups' eec0917 Add granola recipe and README
Seeing the branch structure
--graph draws the history's shape on the left. Combined with --oneline and --all (every branch, not just the current one), it's the best overview of a repository:
git log --oneline --graph --all
* beae5af (HEAD -> main) Add cheese to omelette * 9721f6b Merge branch 'soups' |\ | * eda718c (soups) Add tomato soup * | eec0917 Add granola recipe and README |/ * cfe25ef Add sugar to pancakes * 90c0089 Add omelette recipe * c4f5e47 Add pancake recipe
Many people save this as an alias, such as git lg (lesson 43).
What changed in each commit
--stat lists the files each commit touched:
git log --stat -2
commit beae5af33c0a9f731b34be23798823ecc2a69fad (HEAD -> main)
Author: Sam Rivera <sam@example.com>
Date: Mon Mar 2 10:31:00 2026 +0000
Add cheese to omelette
omelette.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
commit 9721f6b1ccc660e53c5a86bb95c868e86cc3917f
Merge: eec0917 eda718c
Author: Sam Rivera <sam@example.com>
Date: Mon Mar 2 10:24:00 2026 +0000
Merge branch 'soups'-p (--patch) shows the full line-by-line changes, in the same format as git diff (next lesson):
git log -p -1
commit beae5af33c0a9f731b34be23798823ecc2a69fad (HEAD -> main)
Author: Sam Rivera <sam@example.com>
Date: Mon Mar 2 10:31:00 2026 +0000
Add cheese to omelette
diff --git a/omelette.txt b/omelette.txt
index b4927c2..671eb8e 100644
--- a/omelette.txt
+++ b/omelette.txt
@@ -1 +1 @@
-Omelette: eggs, butter
+Omelette: eggs, butter, cheeseFiltering
| Option | Shows commits… |
|---|---|
--author="Alex" | whose author name or email contains the text |
--grep="soup" | whose message contains the text (add -i to ignore case) |
--since="2 weeks ago", --until="2026-03-01" | in a date range (--after and --before also work) |
-- pancakes.txt | that changed a particular file or folder |
--no-merges / --merges | excluding or only merge commits |
-S"sugar" | that added or removed that text in the code (lesson 40) |
git log --oneline --author="Alex"
eec0917 Add granola recipe and README
git log --oneline -- pancakes.txt
cfe25ef Add sugar to pancakes c4f5e47 Add pancake recipe
The -- separates options from file names. It's optional when the name can't be confused with a branch, but a good habit.
git log --oneline --since="2026-03-02 09:40" --no-merges
beae5af (HEAD -> main) Add cheese to omelette eec0917 Add granola recipe and README eda718c (soups) Add tomato soup
Custom formats
--format (also spelled --pretty=format:) lets you choose exactly what to print using placeholders:
git log --format="%h %an, %ar: %s" -3
beae5af Sam Rivera, 70 minutes ago: Add cheese to omelette 9721f6b Sam Rivera, 77 minutes ago: Merge branch 'soups' eec0917 Alex Chen, 84 minutes ago: Add granola recipe and README
| Placeholder | Meaning |
|---|---|
%H / %h | Full / short commit hash |
%an / %ae | Author name / email |
%ad / %ar | Author date / relative date ("3 days ago") |
%s / %b | Subject (summary line) / body |
%d | Branch and tag names pointing at the commit |
Dates can be shown in other styles with --date=short, --date=iso or --date=relative:
git log --format="%ad %s" --date=short -2
2026-03-02 Add cheese to omelette 2026-03-02 Merge branch 'soups'
Oldest first
git log --oneline --reverse
c4f5e47 Add pancake recipe 90c0089 Add omelette recipe cfe25ef Add sugar to pancakes eda718c (soups) Add tomato soup eec0917 Add granola recipe and README 9721f6b Merge branch 'soups' beae5af (HEAD -> main) Add cheese to omelette
Who has contributed
git shortlog groups commits by author. -s shows counts only, -n sorts by number of commits:
git shortlog -sn
6 Sam Rivera
1 Alex ChenTry it yourself
In a repository with a few commits, find: the last two commits with their changed files; every commit that touched one particular file; and the date of the very first commit (use --reverse and a format with %ad).