How to search file content in Git history
Understanding when and why specific code was introduced or removed is essential for debugging, code review, and understanding project evolution.
With over 25 years of software development experience and as the creator of CoreUI, I’ve traced countless code changes through Git history.
Git’s pickaxe options (-S and -G) search through commit diffs to find when specific strings or patterns were added or removed.
This approach helps you discover which commits changed specific functionality, making code archaeology much easier.
Use git log -S to find commits that changed the occurrence count of a specific string in your codebase.
# Find when a string was added or removed
git log -S'functionName'
# Show patches with the changes
git log -S'functionName' -p
# Search in specific file
git log -S'apiKey' -- src/config.js
# Search with regex pattern
git log -G'function.*calculate'
# Case-insensitive search
git log -S'password' -i
# Show one-line summary
git log -S'useState' --oneline
# Search and show only affected files
git log -S'className' --name-only
# Combine with date range
git log -S'deprecated' --since='2025-01-01'
# Search for exact string (not substring)
git log -S'user' --pickaxe-regex
# Show full commit details
git log -S'API_KEY' --pretty=fuller
Difference between -S and -G:
# -S: Finds commits where occurrence count changed
# (Added or removed the string)
git log -S'password'
# -G: Finds commits where the pattern appears in diff
# (Changed lines containing the pattern)
git log -G'password.*hash'
Best Practice Note
Use -S (pickaxe) when looking for when a specific string was added or removed—it’s faster and more precise. Use -G when searching for regex patterns or when you care about any change to lines matching the pattern, not just additions/removals. Combine with -p to see the actual changes in context. Add --all to search across all branches, not just the current one. This is how we track code evolution in CoreUI—using pickaxe to find when features were added, bugs were introduced, or APIs were changed across years of development history.



