0
0
Gitdevops~10 mins

Searching history with git log -S - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Searching history with git log -S
Start: User runs git log -S"text"
Git scans commits
Check each commit diff for added/removed 'text'
If found, include commit in output
Display matching commits
End
The git log -S command scans commit history to find commits that added or removed a specific text string, then shows those commits.
Execution Sample
Git
git log -S"fix bug" --oneline
# Shows commits where 'fix bug' was added or removed
This command searches commit history for changes adding or removing the phrase 'fix bug' and lists those commits briefly.
Process Table
StepActionCommit CheckedText Found in Diff?Include in Output
1Check commit abc123abc123NoNo
2Check commit def456def456Yes (added 'fix bug')Yes
3Check commit 789abc789abcNoNo
4Check commit 456def456defYes (removed 'fix bug')Yes
5Check commit 123789123789NoNo
6End of commits---
💡 All commits checked; output includes only commits where 'fix bug' was added or removed.
Status Tracker
VariableStartAfter 1After 2After 3After 4After 5Final
Current Commit-abc123def456789abc456def123789-
Text FoundFalseFalseTrueFalseTrueFalse-
Output List[][][def456][def456][def456, 456def][def456, 456def][def456, 456def]
Key Moments - 2 Insights
Why does git log -S only show commits where the text was added or removed, not just present?
Because git log -S searches for changes that add or remove the exact text, not just commits containing the text. See execution_table rows 2 and 4 where text was added or removed, so those commits are included.
What happens if the text appears in a commit but was not changed in that commit?
That commit is not included because git log -S looks for changes adding or removing the text, not just presence. See execution_table rows 1 and 3 where text was not found in the diff, so commits are excluded.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, which commit was the first to include the searched text change?
Adef456
B789abc
Cabc123
D456def
💡 Hint
Check the 'Text Found in Diff?' column in the execution_table for the first 'Yes'.
At which step does the output list first include a commit?
AAfter step 1
BAfter step 2
CAfter step 3
DAfter step 4
💡 Hint
Look at the 'Output List' variable in variable_tracker after each step.
If the text was only removed but never added, which commits would git log -S show?
AOnly commits where text was added
BAll commits containing the text
COnly commits where text was removed
DNo commits
💡 Hint
git log -S shows commits where text was added or removed, see execution_table rows 2 and 4.
Concept Snapshot
git log -S"text"
Searches commit history for commits that add or remove 'text'.
Only commits with changes adding/removing the exact string appear.
Useful to find when a specific code or text change happened.
Combine with options like --oneline for brief output.
Full Transcript
The git log -S command helps find commits where a specific text was added or removed. It scans each commit's changes (diffs) and includes only those commits where the searched text appears as a change, not just present. For example, running git log -S"fix bug" lists commits that added or removed the phrase 'fix bug'. The execution table shows step-by-step how git checks each commit and decides whether to include it based on the presence of the text in the diff. Variables track the current commit, whether the text was found, and the growing list of output commits. Key points are that git log -S focuses on changes, not just presence, and that commits without changes to the text are excluded. This helps developers quickly find when a bug fix or feature was introduced or removed in the code history.