How can you filter and format git log output to inspect history effectively?
Last updated
git log becomes powerful once you combine filters (which commits) with formatting (how they display), letting you narrow history to exactly what you're investigating.
Filter which commits appear:
By time:
--since,--until(e.g.--since="2 weeks ago").By author or message:
--author="Ana",--grep="fix".By file or path:
git log -- path/to/file.By content change:
-S"string"(pickaxe) finds commits that added/removed that string;-pshows the actual diffs.
Format how they display:
--onelinefor a compact one-line-per-commit view.--graphdraws the branch/merge topology as ASCII.--pretty=format:...builds a custom line with placeholders like%h(hash),%an(author),%ar(relative date),%s(subject).
Combine them: filters and format flags stack in one command, which is what makes
git loga real inspection tool.
[lang:bash]
git log --oneline --graph --since="1 month ago" --author="Ana"
git log --pretty=format:"%h %an %ar %s" -- src/app.py