Bash

Find Commit That Introduced a String

admin by @admin ADMIN
1h ago
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
`git log -S` (the "pickaxe") finds commits whose diff added or removed a given string. The fastest way to answer "when did this line first appear?"
Bash
Raw
# Find commits that added/removed the string "DEPRECATED_API"
git log -S "DEPRECATED_API" --pretty=format:'%h %ad %an  %s' --date=short

# Same but for a regex (-G instead of -S)
git log -G "deprecated.*api" --pretty=format:'%h %s' -i

# Restrict to a path
git log -S "TODO" -- src/

# Show the diff of the commit that introduced something
git log -S "function calculatePrice" -p

# `git blame` for the line-by-line author of a file
git blame src/payment.js -L 100,150
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.