How can you filter and format git log output to inspect history effectively?

Last updated 6 July 2026

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; -p shows the actual diffs.

  • Format how they display:

    • --oneline for a compact one-line-per-commit view.

    • --graph draws 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 log a 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

  • https://git-scm.com/docs/git-log
  • https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History
  • https://www.atlassian.com/git/tutorials/git-log
  • https://www.geeksforgeeks.org/git/how-to-use-git-log-to-format-the-commit-history/
All Git interview questions