Git Log and History

Git history is one of the main reasons to use Git. The git log command lists past commits, and related commands let you see exactly what changed, when and by whom.

Basic git log

The newest commit appears first. Press q to quit the pager and the arrow keys or space to scroll.

git log
commit 9e1f3b7c2d... (HEAD -> main)
Author: Naeem Amin <you@example.com>
Date:   Fri Oct 30 14:02:11 2026 +0500

    Add contact form

commit a1b2c3d4e5...
Author: Naeem Amin <you@example.com>
Date:   Thu Oct 29 09:45:30 2026 +0500

    Add README

Compact and Graph Views

--graph draws branches as lines, and --all includes every branch, which is very helpful once you start branching.

git log --oneline
git log --oneline --graph --all
9e1f3b7 (HEAD -> main) Add contact form
a1b2c3d Add README

* 4d5e6f7 (feature/blog) Add blog page
| * 9e1f3b7 (HEAD -> main) Add contact form
|/
* a1b2c3d Add README

Filtering the Log

git log -n 5                       # last 5 commits
git log --author="Naeem"           # by author
git log --since="2 weeks ago"      # by date
git log --grep="fix"               # message contains "fix"
git log -- src/App.jsx             # commits touching a file
git log -S "apiKey"                # commits that added/removed text
(each prints only the matching commits)

Inspecting a Commit with git show

HEAD means the current commit; HEAD~1 is its parent, HEAD~2 the one before, and so on. git show commit:path prints a file as it was in that commit.

git show 9e1f3b7 --stat
git show HEAD~1:README.md
commit 9e1f3b7...
    Add contact form

 contact.html | 24 ++++++++++++++++++++++++
 style.css    |  6 ++++++
 2 files changed, 30 insertions(+)

Comparing Versions

git diff a1b2c3d 9e1f3b7          # between two commits
git diff main feature/blog         # between two branches
git diff HEAD~3 -- style.css       # one file vs 3 commits ago
diff --git a/style.css b/style.css
+.contact { max-width: 40rem; }

Who Changed This Line? git blame

git blame shows the last commit and author for each line of a file. It is a tool for understanding context, not for blaming people.

git blame -L 10,14 src/App.jsx
9e1f3b7 (Naeem Amin 2026-10-30 10) export default function App() {
a1b2c3d (Sara Khan  2026-10-21 11)   const [theme, setTheme] = useState('dark');

Frequently asked questions

How do I see commit history in Git?

Run git log. Add --oneline for a compact list, --graph --all to see branches, and -p to show the changes in each commit.

What does HEAD mean in Git?

HEAD is a pointer to the commit you currently have checked out, usually the latest commit on your current branch.

How do I see the changes in a specific commit?

Use git show <commit-hash>. Add --stat for a summary of changed files instead of the full diff.