Skip to content

Git Commit Forensics Quick Reference ​

At-a-glance commands for git log querying, blame, and forensics.

GoalCommand
Find when a string appearedgit log -S "redis://" -p --oneline
Regex content searchgit log -G "password.*=" --oneline -p
Search all branchesgit log --all -S "TOKEN" --oneline
Show full diff per matchgit log -S "v1.2.3" --pickaxe-all -p
Restrict to a filegit log -S "JWT_SECRET" -- config/app.ts

Clean mainline history ​

bash
git log --oneline --first-parent main        # only merge-boundary commits
git log --oneline --first-parent --merges    # only merge commits
git shortlog --first-parent v1.0..HEAD       # release notes by author

File lifecycle tracking ​

bash
git log --diff-filter=A --oneline -- README.md          # when added
git log --diff-filter=D --oneline -- config.yaml        # when deleted
git log --follow --diff-filter=R --oneline -- src/util   # renames
git log --diff-filter=M --name-only v1..v2              # modified files
git diff-tree --no-commit-id -r --name-status SHA1 SHA2  # fast CI diff

Function tracking ​

bash
git log -L :functionName:src/file.ts -p        # track through refactors
git log -L 50,80:src/file.ts                   # track line range

Clean blame ​

bash
git blame --ignore-revs-file=.git-blame-ignore-revs file.ts
git blame --ignore-rev abc1234 file.ts
git blame --porcelain file.ts | grep "^author " | sort -u

Release notes from structured commits ​

bash
git log --oneline --first-parent --grep="^feat" v1.0..HEAD
git log --oneline --first-parent --grep="^fix"  v1.0..HEAD
git log --oneline --first-parent --grep="BREAKING" v1.0..HEAD

Build stamping ​

bash
git describe --tags --always --dirty          # v2.4.0-12-gabc1234
git describe --tags --abbrev=0                # just the tag name

Branch and tag governance ​

bash
git for-each-ref --sort=-committerdate refs/heads/ --format="%(committerdate:short) | %(ref)"
git for-each-ref --sort=-creatordate refs/tags/ --format="%(creatordate:short) | %(ref) | %(subject)"
git rev-list --count branch --not main       # commits ahead of main

Topology-aware history ​

bash
git log --oneline --ancestry-path v1.0..HEAD       # direct DAG path only
git log --oneline --first-parent --ancestry-path    # clean mainline only

CI preflight checks ​

bash
# Skip CI if only docs changed
git diff-tree --no-commit-id -r --name-only HEAD~1 HEAD \
  | grep -q -v "^docs/" || echo "skip CI"

# Detect if package.json changed in a PR
base=$(git merge-base origin/main HEAD)
git diff-tree --no-commit-id -r --name-only "$base" HEAD \
  | grep -q "package.json" && echo "deps changed"

See docs/devops-workflows/git-commit-forensics-querying.md for full guide and scripts/commit-forensics.sh for the automation script.

Git Master — Git Reference for Every Skill Level