Exploring History - log

git log like a pro

Quick refresher on why commits have those cryptic-looking hashes like a1b2c3d: every commit's full identifier is a 40-character SHA-1 hash computed from its own content (snapshot, parent, author, message). Two different commits will (for all practical purposes) never produce the same hash - which is what lets Git reliably refer to any commit, anywhere, by that one string. You'll almost always see and use just the first 7-8 characters, which is normally unique enough to be unambiguous in a given repo.

The raw git log is verbose - one full paragraph per commit. These flags make it genuinely useful day to day:

CommandShows
git log --onelineOne compact line per commit (short hash + message)
git log --graph --oneline --allAn ASCII drawing of the branch/merge structure
git log -pThe full patch (diff) for each commit, not just the message
git log --statWhich files changed, and by how many lines, per commit
git log --author="Alice"Filter to one author
git log --since="2 weeks ago"Filter by date
git log -- path/to/fileOnly commits that touched one specific file
git log -S"functionName"Commits that added or removed that exact text ("pickaxe" search)
$ git log --oneline --graph --all
* a1b2c3d (HEAD -> main) Merge feature-login
|\
| * 9f8e7d6 (feature-login) Add login form
* | 7c6b5a4 Update README
|/
* 000aaa1 Initial commit

In that graph, the |\ and |/ characters show where feature-login split off from main and where it merged back in - the same shape as the merge diagrams from the Branching module, just rendered in the terminal.

Tip: git log -S"getUser" (pickaxe) is a debugging superpower: it finds the exact commit where a string first appeared or disappeared from the codebase - perfect for answering "when did this function get deleted, and by whom?" without scrolling through hundreds of commits by hand.