Git·19 questions

How to view commit history and find a specific commit?

Answer

Commit history is the main tool for understanding what and when changed in a project. Git offers several ways to view and search.

Basic viewing: git log shows history in reverse chronological order — latest commits at the top. Each commit contains a hash, author, date, and message. The command git log --oneline shows a compact format — one commit per line, only hash and message. Useful for reviewing large history.

Filtering: git log -5 shows the last 5 commits. git log --author="John" filters by author. git log --since="2 weeks ago" — commits from the last 2 weeks. git log --since="2026-01-01" --until="2026-06-01" — date range. git log -- <file> shows only commits touching a specific file.

Searching by message: git log --grep="auth" searches for commits with a keyword in the message. The -i flag makes the search case-insensitive: git log --grep="auth" -i. You can search with regex: git log --grep="fix\(.*\)".

Visualization: git log --graph --oneline --all shows the branch tree as a graph — useful for understanding merge structure. The --all flag includes all branches, not just the current one. Alternative: git log --graph --oneline --decorate — adds branch and tag labels.

Changes in a commit: git show <hash> shows the full diff of a specific commit. git show HEAD — the latest commit. git show HEAD~2 — the third from the end. The command git diff <hash1>..<hash2> shows the difference between two commits.

Finding a bug with bisect: git bisect start, git bisect bad (current commit is broken), git bisect good <hash> (this commit worked). Git automatically checks out commits in the middle of the range. You test and mark git bisect good or git bisect bad. Git finds the commit that introduced the bug. Finish: git bisect reset.

Blame: git blame <file> shows who wrote each line of a file and in which commit. Useful for understanding the context of changes. git blame -L 10,20 <file> — only lines 10-20.

Was this answer helpful?

More questions in this topic

Related questions from other topics