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.
Shows the commit history in reverse chronological order.
commit abc1234def5678ghi9012jkl3456mno7890pqr
Date: Mon Feb 5 14:00:00 2024 +0300
commit def5678ghi9012jkl3456mno7890pqrstu1234
Date: Mon Feb 5 10:30:00 2024 +0300
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
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
Shows the patch (diff) for each commit along with commit info.
commit abc1234def5678ghi9012jkl3456mno7890pqr
Date: Mon Feb 5 14:00:00 2024 +0300
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');
}
Shows commits that affected a specific file.
commit abc1234def5678ghi9012jkl3456mno7890pqr
Date: Mon Feb 5 14:00:00 2024 +0300
commit def5678ghi9012jkl3456mno7890pqrstu1234
Date: Fri Feb 2 09:15:00 2024 +0300
Shows commits by a specific author (supports regex).
git log --author="John\|Jane" # Multiple authors
commit abc1234def5678ghi9012jkl3456mno7890pqr
Date: Mon Feb 5 14:00:00 2024 +0300
commit jkl3456mno7890pqrstu1234vwxy5678zab9012
Date: Fri Feb 2 11:30:00 2024 +0300
Shows commits within a specific date range.
git log --after="2 weeks ago"
commit def5678ghi9012jkl3456mno7890pqrstu1234
Date: Mon Jan 15 10:30:00 2024 +0300
commit ghi9012jkl3456mno7890pqrstu1234vwxy5678
Date: Wed Jan 10 14:20:00 2024 +0300
git log -i --grep="bugfix" # Case-insensitive
Searches commit messages for specific text (supports regex).
commit a4ffb5edfcd96d33052cc5b4d8c562db3556eae4
Date: Mon Jul 28 11:58:05 2025 +0530
commit cd555b7157a8ac55041b04e7c5e37f166d1eb9c9
Date: Mon Jul 28 09:57:04 2025 +0530
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
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
Shows insertions/deletions statistics for each commit.
commit 1f92a34a422fb4417f8f779f114a8b1361768b6c (HEAD ->
master, origin/master, origin/HEAD)
Date: Mon Jul 28 16:08:32 2025 +0530
1 file changed, 1 insertion(+), 1 deletion(-)
commit fc2a6d40d88339031419508a87eb98087796c8f7
Date: Mon Jul 28 09:35:12 2025 +0000
54 files changed, 10 insertions(+), 12351 deletions(-)
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
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
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>
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
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>
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
Shows the evolution of a specific function in a file.
commit abc1234def5678ghi9012jkl3456mno7890pqr
Date: Mon Feb 5 14:00:00 2024 +0300
@@ -10,7 +10,7 @@ function authenticate(req, res, next) {
- if (!req.session.user) {
+ if (!req.user || !req.user.isAuthenticated) {
return res.redirect('/login');
}
Finds commits that don't contain "bug" in message but contain "TODO" in code.
commit def5678ghi9012jkl3456mno7890pqrstu1234
Date: Mon Feb 5 10:30:00 2024 +0300
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="yesterday"
git log --after="last monday" --before="last friday" # Last week's commits
Shows today's commits by a specific author.
commit abc1234def5678ghi9012jkl3456mno7890pqr
Date: Mon Feb 5 14:00:00 2024 +0300
commit jkl3456mno7890pqrstu1234vwxy5678zab9012
Date: Mon Feb 5 11:30:00 2024 +0300
Shows the history of changes to specific lines (10-20) in a file.
commit abc1234def5678ghi9012jkl3456mno7890pqr
Date: Mon Feb 5 14:00:00 2024 +0300
@@ -12,5 +12,5 @@
- <title>Old Title</title>
+ <title>New Title</title>
<meta name="description" content="Website
description">
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
Generates a report of last week's work (excluding merge commits).
commit def5678ghi9012jkl3456mno7890pqrstu1234
Date: Thu Feb 1 10:30:00 2024 +0300
commit ghi9012jkl3456mno7890pqrstu1234vwxy5678
Date: Wed Jan 31 14:20:00 2024 +0300
Shows commits in your local branch that haven't been pushed to origin.
commit abc1234def5678ghi9012jkl3456mno7890pqr
Date: Mon Feb 5 14:00:00 2024 +0300
commit jkl3456mno7890pqrstu1234vwxy5678zab9012
Date: Mon Feb 5 11:30:00 2024 +0300
Finds commits that contain any of the specified terms in their messages.
commit abc1234def5678ghi9012jkl3456mno7890pqr
Date: Mon Feb 5 14:00:00 2024 +0300
commit def5678ghi9012jkl3456mno7890pqrstu1234
Date: Fri Feb 2 09:15:00 2024 +0300
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>'