Chapter 10: Git History
Git History — the beautiful, powerful timeline that makes Git feel like magic once you learn to read it.
Git history is simply the complete record of every commit ever made in your repository. Every time someone runs git commit, Git adds a new entry to this chain. It’s not just a list — it’s a directed acyclic graph (DAG) of snapshots, each pointing back to its parent(s).
Why care about history?
- See who changed what and when (blame / accountability)
- Understand why something broke (bisect bugs)
- Go back in time to any working version
- Review team progress
- Write changelogs / release notes
- Impress interviewers when they say “show me your commit history”
Let’s build a tiny example repo together so you see exactly what history looks like in practice.
Step 1 – Create a playground with realistic commits
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
mkdir git-history-demo cd git-history-demo git init # Commit 1 – Start echo "# My Awesome Todo App" > README.md git add README.md git commit -m "Initial commit: project skeleton + README" # Commit 2 echo "- Buy groceries" >> README.md git add README.md git commit -m "Add first todo item to README" # Commit 3 – new file echo "<h1>Todo List</h1>" > index.html git add index.html git commit -m "Add basic HTML structure" # Commit 4 – style echo "body { font-family: Arial; background: #f8f9fa; }" > style.css git add style.css git commit -m "Add minimal CSS styling" # Commit 5 – feature branch simulation git checkout -b feature/add-javascript echo "<script>alert('Todo app loading...');</script>" >> index.html git add index.html git commit -m "Add simple JS alert on load" # Back to main + merge git checkout main git merge feature/add-javascript --no-edit # fast-forward merge # Commit 6 – after merge echo "- Learn Git history commands" >> README.md git add README.md git commit -m "Update README: add history learning goal" |
Now we have 6 commits with a tiny branch & merge.
Step 2 – The Most Important Command: git log
This is your window into history.
Basic view (full details)
|
0 1 2 3 4 5 6 |
git log |
Output looks like (newest first):
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
commit 89abcde1234567890fedcba9876543210fedcba9 (HEAD -> main) Author: Webliance <webliance@example.com> Date: Fri Feb 13 14:20:00 2026 +0530 Update README: add history learning goal commit def1234567890abcdef1234567890abcdef12 Merge: 4567890 abcdef1 Author: Webliance <...> Date: Fri Feb 13 14:15:00 2026 +0530 Merge branch 'feature/add-javascript' commit 4567890abcdef1234567890abcdef12345678 (feature/add-javascript) Author: ... Date: ... Add simple JS alert on load commit abcdef1234567890abcdef1234567890abcde Author: ... Date: ... Add minimal CSS styling ... (and so on down to initial commit) |
Too verbose? Let’s make it beautiful and useful.
Step 3 – Pretty & Practical Ways to View History (Daily Drivers in 2026)
1. One-line summary – most used
|
0 1 2 3 4 5 6 |
git log --oneline |
|
0 1 2 3 4 5 6 7 8 9 10 11 12 |
89abcde Update README: add history learning goal def1234 Merge branch 'feature/add-javascript' 4567890 Add simple JS alert on load abcdef1 Add minimal CSS styling 1234567 Add basic HTML structure 789abcd Add first todo item to README fedcba9 Initial commit: project skeleton + README |
2. Pretty graph + branches (my personal favorite)
|
0 1 2 3 4 5 6 |
git log --graph --oneline --decorate --all |
Or shorter alias (add this once globally):
|
0 1 2 3 4 5 6 |
git config --global alias.lg "log --graph --oneline --decorate --all" |
Then just run:
|
0 1 2 3 4 5 6 |
git lg |
Typical beautiful output:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 |
* 89abcde (HEAD -> main) Update README: add history learning goal * def1234 Merge branch 'feature/add-javascript' |\ | * 4567890 (feature/add-javascript) Add simple JS alert on load * | abcdef1 Add minimal CSS styling * 1234567 Add basic HTML structure * 789abcd Add first todo item to README * fedcba9 Initial commit: project skeleton + README |
→ See merge bubbles, branch names, HEAD position — gold!
3. Last 5 commits only
|
0 1 2 3 4 5 6 |
git log -5 --oneline --graph |
4. Who changed what (blame-style summary)
|
0 1 2 3 4 5 6 7 8 |
git log --oneline --author="Webliance" git log --oneline --since="2026-02-01" git log --oneline --until="yesterday" |
5. See actual code changes in history
|
0 1 2 3 4 5 6 |
git log -p # -p = patch/show diff for each commit |
Or for one file:
|
0 1 2 3 4 5 6 |
git log -p -- README.md |
6. See only file names changed per commit
|
0 1 2 3 4 5 6 |
git log --name-only --oneline |
7. Statistics – how many lines added/removed
|
0 1 2 3 4 5 6 |
git log --stat -2 # last 2 commits with stats |
Example snippet:
|
0 1 2 3 4 5 6 7 8 |
89abcde Update README: add history learning goal README.md | 1 + 1 file changed, 1 insertion(+) |
Step 4 – Even More Powerful History Tools
-
git show → zoom into one commit
Bash01234567git show 89abcde # full diff + messagegit show 89abcde:README.md # view file as it was at that commit -
git blame → line-by-line who/when
Bash0123456git blame README.mdShows commit hash + author + date for each line
-
git reflog → your personal undo history (even commits you “lost”)
Bash0123456git reflogtext01234567889abcde HEAD@{0}: commit: Update README...def1234 HEAD@{1}: merge feature/add-javascript: Merge made by the 'ort' strategy....Super useful when you accidentally reset hard or lose a branch.
Quick Summary Table – Your Git History Cheat Sheet
| What you want to see | Best Command | Why it’s useful |
|---|---|---|
| Simple list | git log –oneline | Fast overview |
| Branches & merges visualized | git lg (alias) or –graph –decorate –all | Understand team workflow |
| Last N commits | git log -n 10 –oneline –graph | Recent activity |
| Changes in a commit | git show <hash> or git log -p -1 | Code review / debug |
| Who touched a file (line by line) | git blame <file> | “Who broke this line?” |
| Personal safety net / undo history | git reflog | Recover “lost” commits |
| Stats (lines changed) | git log –stat | See impact size |
Homework for today:
- In any repo → run git lg or git log –graph –oneline –decorate –all
- Pick a commit hash → git show <hash>
- Try git blame on a file with multiple commits
Got the history vision now? Next class — want to learn git bisect (find which commit broke something)? Or git diff across history? Or how to rewrite history safely?
Just tell me — we’re building this together step by step. You’re getting seriously good at Git! 🚀
