Complete Git Log Command Reference

Master the art of exploring commit history in Git

Git log is an essential tool for exploring your repository's history. This comprehensive guide covers all essential git log commands with practical examples to help you become a Git log expert.

Table of Contents

Basic Log Commands

git log Basic Log

Shows the commit history in reverse chronological order.

commit abc1234def5678ghi9012jkl3456mno7890pqr Author: John Doe <john@example.com> Date: Mon Feb 5 14:00:00 2024 +0300 Update authentication middleware commit def5678ghi9012jkl3456mno7890pqrstu1234 Author: Jane Smith <jane@example.com> Date: Mon Feb 5 10:30:00 2024 +0300 Add user profile page
git log -n 5 Limit Output

git log --patch-with-stat (Stats + diffs)

Shows only the last 5 commits (replace 5 with any number).

commit abc1234 (HEAD -> main) Fix login bug commit def5678 Add user profile commit ghi9012 Update README commit jkl3456 Refactor API routes commit mno7890 Initial commit
git log --oneline Compact View

Shows each commit on a single line with abbreviated commit hash.

abc1234 (HEAD -> main) Fix login bug def5678 Add user profile ghi9012 Update README jkl3456 Refactor API routes mno7890 Initial commit
git log -p Patch Output

Shows the patch (diff) for each commit along with commit info.

commit abc1234def5678ghi9012jkl3456mno7890pqr Author: John Doe <john@example.com> Date: Mon Feb 5 14:00:00 2024 +0300 Update authentication middleware diff --git a/src/middleware/auth.js b/src/middleware/auth.js index a1b2c3d..e4f5g6h 100644 --- a/src/middleware/auth.js +++ b/src/middleware/auth.js @@ -10,7 +10,7 @@ function authenticate(req, res, next) { - if (!req.session.user) { + if (!req.user || !req.user.isAuthenticated) { return res.redirect('/login'); }

Filtering & Searching

git log -- path/to/file.js File History

Shows commits that affected a specific file.

commit abc1234def5678ghi9012jkl3456mno7890pqr Author: John Doe <john@example.com> Date: Mon Feb 5 14:00:00 2024 +0300 Update authentication logic commit def5678ghi9012jkl3456mno7890pqrstu1234 Author: Jane Smith <jane@example.com> Date: Fri Feb 2 09:15:00 2024 +0300 Initial implementation
git log --author="John" Filter by Author

Shows commits by a specific author (supports regex).

git log --author="John\|Jane" # Multiple authors

commit abc1234def5678ghi9012jkl3456mno7890pqr Author: John Doe <john@example.com> Date: Mon Feb 5 14:00:00 2024 +0300 Update authentication middleware commit jkl3456mno7890pqrstu1234vwxy5678zab9012 Author: John Doe <john@example.com> Date: Fri Feb 2 11:30:00 2024 +0300 Add password reset functionality
git log --since="2024-01-01" --until="2024-02-01" Date Range

Shows commits within a specific date range.

git log --after="2 weeks ago"

commit def5678ghi9012jkl3456mno7890pqrstu1234 Author: Jane Smith <jane@example.com> Date: Mon Jan 15 10:30:00 2024 +0300 Add user profile page commit ghi9012jkl3456mno7890pqrstu1234vwxy5678 Author: John Doe <john@example.com> Date: Wed Jan 10 14:20:00 2024 +0300 Fix database connection issue
git log --grep="bug" Search Messages

git log -i --grep="bugfix" # Case-insensitive

Searches commit messages for specific text (supports regex).

commit a4ffb5edfcd96d33052cc5b4d8c562db3556eae4 Author: akash.kumar <akash.kumar@msllearning.com> Date: Mon Jul 28 11:58:05 2025 +0530 added url gcs mou commit cd555b7157a8ac55041b04e7c5e37f166d1eb9c9 Author: akash.kumar <akash.kumar@msllearning.com> Date: Mon Jul 28 09:57:04 2025 +0530 gcs url set replaced s3 url in resources

Formatting Output

git log --pretty=format:"%h - %an, %ar : %s" Custom Format

Customizes the output format with placeholders.

1f92a34a - nishu.pandey, 2 hours ago : changes fc2a6d40 - root, 3 hours ago : storage log ignored 29f19071 - root, 3 hours ago : ignored vendore ac6cbc6c - nishu.pandey, 3 hours ago : changes
git log --pretty=format:"%h | %ad | %an | %s" --date=short Table Format

Formats log output in a table-like structure for easy reading.

abc1234 | 2024-02-05 | John Doe | Update authentication middleware def5678 | 2024-02-04 | Jane Smith | Add user profile page ghi9012 | 2024-02-03 | John Doe | Fix security issue jkl3456 | 2024-02-01 | Jane Smith | Initial commit
git log --shortstat Statistics

Shows insertions/deletions statistics for each commit.

commit 1f92a34a422fb4417f8f779f114a8b1361768b6c (HEAD -> master, origin/master, origin/HEAD) Author: nishu.pandey <nishu.pandey@msllearning.com> Date: Mon Jul 28 16:08:32 2025 +0530 changes 1 file changed, 1 insertion(+), 1 deletion(-) commit fc2a6d40d88339031419508a87eb98087796c8f7 Author: root <root@outreach.c.u18-outreach.internal> Date: Mon Jul 28 09:35:12 2025 +0000 storage log ignored 54 files changed, 10 insertions(+), 12351 deletions(-)
git log --numstat --pretty="%h - %an, %ad : %s" Line Changes

Shows line changes per file in a custom format.

abc123 - John, Mon Feb 5 14:00:00 2024 : Update auth 3 2 src/auth.js 0 5 tests/auth.test.js def456 - Jane, Mon Feb 5 10:30:00 2024 : Add profile 15 0 src/profile.js 8 1 tests/profile.test.js
git log --pretty=format: '{"commit":"%h", "date":"%ai", "author":"%aN", "message":"%s"}' --numstat JSON Output

Formats output as JSON for programmatic processing.

{ "commit": "abc123", "date": "2024-02-05 14:00:00 +0300", "author": "John Doe", "message": "Update auth", "files": [ {"insertions": 3, "deletions": 2, "path": "src/auth.js"} ] } 2 1 .gitignore 8 8 config/database.php 0 3 storage/app/.gitignore

Graph Visualization

git log --graph --oneline --all Branch Graph

Shows commit history with ASCII graph of branches.

* 1f92a34a - (HEAD -> master, origin/master, origin/HEAD) changes (2 hours ago) <nishu.pandey> * fc2a6d40 - storage log ignored (3 hours ago) <root> * 29f19071 - ignored vendore (3 hours ago) <root> * ac6cbc6c - changes (3 hours ago) <nishu.pandey>
git log --graph --pretty=format:'%Cred%h%Creset - %C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative Colored Graph

Shows a colorful graph with relative dates and branch info.

* 1f92a34a (HEAD -> master, origin/master, origin/HEAD) changes * fc2a6d40 storage log ignored * 29f19071 ignored vendore * ac6cbc6c changes * a4ffb5ed added url gcs mou * 78e05705 Merge branch 'master' of https://bitbucket.org/unextt/outreach_8 * db726da3 Merge branch 'master' of https://bitbucket.org/unextt/outreach_8 |\ | * 79949914 .gitignore edited online with Bitbucket * | cd555b71 gcs url set replaced s3 url in resources |/ * cb488d8a added fetures files aceess through gcs and also local file access through gcs previously use localstorage
git log --graph --all --date-order --pretty=format:'%C(auto)%h%d %s %C(green)(%ad) %C(blue)<%an>' Advanced Graph

Shows a detailed graph with automatic coloring, date ordering, and custom format.

* abc1234 (HEAD -> main) Update auth (2024-02-05) <John Doe> * def5678 (origin/feature) Add profile (2024-02-04) <Jane Smith> | * ghi9012 (hotfix) Fix security issue (2024-02-03) <John Doe> |/ * jkl3456 Initial commit (2024-02-01) <Jane Smith>
git log --simplify-by-decoration --decorate --oneline --all Branch Topology

Shows a simplified view of branch topology with only decorated commits.

45a9d85 (HEAD -> master) text, ui and lanaguge implemented 60616c5 (origin/master) changes 027e866 (refs/stash) WIP on master: a122e86 added synopsis extended date a122e86 (new-student-panel-july-2025) added synopsis extended date bce5381 (origin/student-new-feb-2025) made the moodle data fetching dynamic 63249ae (origin/apk-api-feb-2025) global file added 7477ea3 updated

Advanced Techniques

git log -L :function_name:file.js Function History

Shows the evolution of a specific function in a file.

commit abc1234def5678ghi9012jkl3456mno7890pqr Author: John Doe <john@example.com> Date: Mon Feb 5 14:00:00 2024 +0300 Refactor authenticate function @@ -10,7 +10,7 @@ function authenticate(req, res, next) { - if (!req.session.user) { + if (!req.user || !req.user.isAuthenticated) { return res.redirect('/login'); }
git log --grep="bug" --invert-grep --pickaxe-regex -S"TODO" --perl-regexp Complex Search

Finds commits that don't contain "bug" in message but contain "TODO" in code.

commit def5678ghi9012jkl3456mno7890pqrstu1234 Author: Jane Smith <jane@example.com> Date: Mon Feb 5 10:30:00 2024 +0300 Add user profile page diff --git a/src/profile.js b/src/profile.js index e4f5g6h..i7j8k9l 100644 --- a/src/profile.js +++ b/src/profile.js @@ -15,3 +15,5 @@ function renderProfile(user) { // Render profile page return html; } + +// TODO: Add email validation
git log --since="9am" --until="5pm" --author="John" Today's Work

git log --since="yesterday"

git log --after="last monday" --before="last friday" # Last week's commits

Shows today's commits by a specific author.

commit abc1234def5678ghi9012jkl3456mno7890pqr Author: John Doe <john@example.com> Date: Mon Feb 5 14:00:00 2024 +0300 Update authentication middleware commit jkl3456mno7890pqrstu1234vwxy5678zab9012 Author: John Doe <john@example.com> Date: Mon Feb 5 11:30:00 2024 +0300 Fix login validation
git log -L 10,20:index.html Line Range History

Shows the history of changes to specific lines (10-20) in a file.

commit abc1234def5678ghi9012jkl3456mno7890pqr Author: John Doe <john@example.com> Date: Mon Feb 5 14:00:00 2024 +0300 Update header section @@ -12,5 +12,5 @@ - <title>Old Title</title> + <title>New Title</title> <meta name="description" content="Website description">
git log --pretty=format:'{"commit":"%h", "date":"%ai", "author":"%aN", "message":"%s"}' --numstat JSON Output

Formats output as JSON for programmatic processing with file statistics.

{ "commit": "abc123", "date": "2024-02-05 14:00:00 +0300", "author": "John Doe", "message": "Update auth", "files": [ {"insertions": 3, "deletions": 2, "path": "src/auth.js"} ] } 2 1 .gitignore 8 8 config/database.php 0 3 storage/app/.gitignore

Workflow Integration

git log --no-merges --since="last monday" --before="last friday" git log --no-merges git log --name-only Weekly Report

Generates a report of last week's work (excluding merge commits).

commit def5678ghi9012jkl3456mno7890pqrstu1234 Author: Jane Smith <jane@example.com> Date: Thu Feb 1 10:30:00 2024 +0300 Add user profile page commit ghi9012jkl3456mno7890pqrstu1234vwxy5678 Author: John Doe <john@example.com> Date: Wed Jan 31 14:20:00 2024 +0300 Fix database connection issue
git log origin/main..main Unpushed Commits

Shows commits in your local branch that haven't been pushed to origin.

commit abc1234def5678ghi9012jkl3456mno7890pqr Author: John Doe <john@example.com> Date: Mon Feb 5 14:00:00 2024 +0300 Update authentication middleware commit jkl3456mno7890pqrstu1234vwxy5678zab9012 Author: John Doe <john@example.com> Date: Mon Feb 5 11:30:00 2024 +0300 Fix login validation
git log --grep="fix" --grep="bug" --grep="issue" --all-match Bug Fix Search

Finds commits that contain any of the specified terms in their messages.

commit abc1234def5678ghi9012jkl3456mno7890pqr Author: John Doe <john@example.com> Date: Mon Feb 5 14:00:00 2024 +0300 Fix login bug commit def5678ghi9012jkl3456mno7890pqrstu1234 Author: Jane Smith <jane@example.com> Date: Fri Feb 2 09:15:00 2024 +0300 Resolve database connection issue
Pro Tip

Create aliases for frequently used git log commands in your ~/.gitconfig file. For example:

[alias] lol = log --graph --oneline --all lola = log --graph --pretty=format:'%Cred%h%Creset - %C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all today = log --since=\"9am\" --oneline --author=\"$(git config user.name)\"
[alias] ljson = log --pretty=format:'{\"commit\":\"%h\",\"date\":\"%ai\",\"author\":\"%aN\",\"message\":\"%s\"}' --numstat lfunc = log -L lsearch = log --grep lgraph = log --graph --all --date-order --pretty=format:'%C(auto)%h%d %s %C(green)(%ad) %C(blue)<%an>'