Quick reference for finding commits in Git with examples.
git log -p -S "<string>" -- <file>- Shows commits where
<string>was added or removed. - Example:
git log -p -S "arg.selectionSet.selections" -- src/index.tscommit abc123
Author: Dev <dev@example.com>
Date: 2025-08-21
+ console.log(arg.selectionSet.selections) # Added line (green)
- console.log(arg.selectionSet.foo) # Removed line (red)Only commits adding or removing the exact string appear.
git log -p -G "<regex>" -- <file>- Shows commits where lines matching regex were changed.
- Example:
git log -p -G "selectionSet" -- src/index.tscommit def456
Author: Dev <dev@example.com>
Date: 2025-08-20
- console.log(arg.selectionSet) # Removed (red)
+ console.log(arg.selectionSet.selections) # Added (green)Any change to lines containing
"selectionSet"is included.
git log -p --all -S "arg.selectionSet.selections" -- src/index.ts
git log -p --all -G "selectionSet" -- src/index.ts--author="<name>" # Filter by author
--since="YYYY-MM-DD" # Filter by date
--oneline # One-line summary per commit| Option | Finds | Use case |
|---|---|---|
-S |
Commits that add/remove exact string | Track when a variable or function was introduced or removed |
-G |
Commits that modify lines matching regex | Track all changes related to a pattern, even partial changes |
Combine with --oneline for faster browsing:
git log -S "myVar" --oneline- Green (+) = lines added
- Red (-) = lines removed
-S→ exact string change only-G→ any line matching pattern changed