Git Log
Purpose
git log displays the commit history of a repository. It is the primary tool for understanding what changed, when, and why — and for locating specific commits.
Architecture
Each commit in the log contains:
- Commit hash (SHA-1) — unique 40-character identifier; typically abbreviated to 7 characters
- Author — name + email of who wrote the change
- Date — when the commit was authored
- Commit message — subject line + optional body
Git walks the commit graph from HEAD backwards through parent pointers to produce the log.
Implementation Notes
Basic log:
git log # full log, oldest last
git log --oneline # one line per commit: short hash + subjectVisualise branch structure:
git log --oneline --decorate --graph # ASCII branch graph
git log --oneline --decorate --graph --all # include all branchesUseful flags:
| Flag | Description |
|---|---|
--oneline | Short hash + subject only |
--decorate | Show branch/tag refs next to commits |
--graph | ASCII graph of branch topology |
--all | Include all branches and remotes |
--parents | Show parent commit hashes |
-n <N> | Limit to last N commits |
--author=<name> | Filter by author |
--since=<date> | Filter by date (e.g. --since="2 weeks ago") |
--grep=<pattern> | Filter by commit message |
--follow <file> | Follow file renames |
-p | Show diff for each commit (patch) |
--stat | Show file change statistics per commit |
Log of a remote branch:
git log origin/mainSearch commit content:
git log -S "function_name" # commits that added/removed string (pickaxe)
git log -G "regex" # commits where diff matches regexReferencing commits:
HEAD~1 # one commit before HEAD
HEAD~3 # three commits before HEAD
<hash> # any commit by (abbreviated) SHATrade-offs
--graph --all --oneline --decorateis verbose but invaluable for understanding complex merge/rebase histories.git log -pproduces a lot of output; pipe tolessor usegit show <hash>to inspect a single commit.--followis necessary when a file was renamed; without it, log stops at the rename.