Q8 of 40 · Git
How do you view the commit history? How do you make it readable?
Short answer
Short answer: git log --oneline --graph --decorate --all gives a compact one-line-per-commit graph with branch labels. Use --author, --since, --grep, or -S 'term' to filter. git log --stat shows changed files per commit. Set up a git alias (git config --global alias.lg 'log --oneline --graph --decorate --all') to avoid retyping.
Detail
Filtering history — practical patterns for QA engineers:
# Find the commit that changed a test file
git log --oneline -- tests/UserApiTest.java
# Search for commits that added or removed a string
git log -S "resetPassword" --oneline
# Commits by a specific author in the last 2 weeks
git log --author="Alice" --since="2 weeks ago" --oneline
# Commits that match a message pattern
git log --grep="fix:" --oneline
Graph view — essential in branchy repos:
git log --oneline --graph --decorate --all shows the full branch tree in ASCII art. It's the fastest way to understand how branches relate and where merges happened.
git show <sha>: view the full diff of a single commit — useful for code-reviewing a specific change or understanding what a commit actually modified.
Setting up a permanent alias in ~/.gitconfig means you type git lg and get the full graph view without memorising flags.
// EXAMPLE
# Useful log alias — add to ~/.gitconfig
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
git lg
# Filter: all commits touching a specific test file
git log --oneline -- src/test/java/UserApiTest.java
# Search commit diffs for a string (the -S "pickaxe" flag)
git log -S "testGetUser" --oneline --all
# Show full diff of a single commit
git show a1b2c3d
# Compare two branches — commits in feature not in main
git log main..feature/login --oneline// WHAT INTERVIEWERS LOOK FOR
// COMMON PITFALL
// Related questions