Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does the -S option do in git log?
The -S option searches for commits that add or remove a specific string in the code. It helps find changes related to that exact text.
Click to reveal answer
intermediate
How is git log -S different from git log -G?
-S searches for changes in the number of occurrences of a string, while -G searches for commits that match a regular expression pattern in the diff.
Click to reveal answer
beginner
Write a command to find commits that added or removed the word 'bugfix' in the project history.
git log -S'bugfix'
Click to reveal answer
intermediate
Can git log -S search for changes in binary files?
No, git log -S works only with text changes. It cannot search inside binary files.
Click to reveal answer
beginner
Why might git log -S be useful when debugging?
It helps find exactly when a specific piece of code was added or removed, making it easier to track down when a bug was introduced or fixed.
Click to reveal answer
What does git log -S'functionName' do?
AShows commits that contain 'functionName' anywhere
BShows commits that deleted 'functionName' only
CShows commits that changed the file named 'functionName'
DShows commits that added or removed 'functionName'
✗ Incorrect
-S finds commits where the number of occurrences of the string changes, so it shows commits that added or removed 'functionName'.
Which option would you use to search commits by a regular expression pattern?
A-p
B-S
C-G
D-a
✗ Incorrect
-G searches commits by matching a regex pattern in the diff.
If you want to find when a variable name was changed, which command helps best?
Agit log -S'variableName'
Bgit log --oneline
Cgit status
Dgit diff
✗ Incorrect
git log -S finds commits that added or removed the variable name.
Does git log -S show commits that only mention the string in commit messages?
AYes, it searches commit messages
BNo, it searches code changes only
CYes, but only for merge commits
DNo, it searches file names only
✗ Incorrect
-S searches for changes in the code, not commit messages.
What is a practical use of git log -S?
ATo find when a specific code line was added or removed
BTo list all branches
CTo merge two branches
DTo clone a repository
✗ Incorrect
git log -S helps find commits that changed a specific string in the code.
Explain how git log -S helps you find when a specific piece of code was added or removed.
Think about how you find when a word first appeared or disappeared in your project.
You got /3 concepts.
Describe the difference between git log -S and git log -G.
One looks for exact string changes, the other for pattern matches.
You got /3 concepts.
Practice
(1/5)
1. What does the git log -S command do?
easy
A. Finds commits that added or removed a specific string in the code.
B. Shows the current status of files in the working directory.
C. Displays the list of branches in the repository.
D. Creates a new branch with the given name.
Solution
Step 1: Understand the purpose of git log -S
This command searches commit history for changes that added or removed a specific string.
Step 2: Compare with other git commands
Other options like git status show file status, git branch lists branches, and git branch <name> creates branches, which are different tasks.
Final Answer:
Finds commits that added or removed a specific string in the code. -> Option A
Quick Check:
Search commits by string change = B [OK]
Hint: Remember: -S searches for string changes in commits [OK]
Common Mistakes:
Confusing -S with showing file status
Thinking it lists branches
Assuming it creates branches
2. Which of the following is the correct syntax to find commits that added or removed the word fix using git log -S?
easy
A. git log -S fix
B. git log -s fix
C. git log --search=fix
D. git log -search fix
Solution
Step 1: Identify correct option flag
The correct flag to search for string changes is uppercase -S, so git log -S fix is correct.
Step 2: Check other options for syntax errors
-s is not valid for this purpose, and --search or -search are not valid git log options.
Final Answer:
git log -S fix -> Option A
Quick Check:
Uppercase -S for string search = A [OK]
Hint: Use uppercase -S to search string changes in git log [OK]
Common Mistakes:
Using lowercase -s instead of -S
Trying non-existent --search option
Adding extra dashes incorrectly
3. Given the following git log command: git log -S 'bugfix' --oneline What will this command output?
medium
A. An error because the string 'bugfix' is not quoted correctly.
B. A list of all commits with the word 'bugfix' anywhere in the commit message.
C. A list of commits that modified files named 'bugfix'.
D. A list of commits that added or removed the string 'bugfix', shown in one line each.
Solution
Step 1: Understand -S 'bugfix' usage
This searches commits that added or removed the exact string 'bugfix' in the code or content.
Step 2: Understand --oneline option
This shows each commit in a short single line format for easy reading.
Final Answer:
A list of commits that added or removed the string 'bugfix', shown in one line each. -> Option D
Quick Check:
-S finds string changes, --oneline shortens output = D [OK]
Hint: Combine -S with --oneline for short commit list by string [OK]
Common Mistakes:
Thinking it searches commit messages instead of code changes
Assuming it filters by file names
Believing quotes cause errors here
4. You run git log -S 'update' but get no results, even though you know the word 'update' was added in some commits. What could be the problem?
medium
A. You need to use git log -G 'update' to search commit messages.
B. You forgot to put quotes around the search string.
C. The string 'update' was only changed in commit messages, not in code.
D. The repository has no commits at all.
Solution
Step 1: Understand what -S searches
-S searches for string changes in the code or content, not in commit messages.
Step 2: Consider commit message search
If 'update' was only added or changed in commit messages, -S won't find it; use git log --grep 'update' to search commit messages. -G searches code diffs by regex.
Final Answer:
The string 'update' was only changed in commit messages, not in code. -> Option C
Quick Check:
-S searches code changes, not commit messages = A [OK]
Hint: Use -G to search commit messages, -S for code changes [OK]
Common Mistakes:
Assuming -S searches commit messages
Thinking quotes cause no results
Believing repository is empty without checking
5. You want to find all commits that added or removed the string TODO but only in the src/ folder. Which command will do this correctly?
hard
A. git log -S 'TODO' --path src/
B. git log -S 'TODO' -- src/
C. git log -S 'TODO' src/
D. git log --S 'TODO' -- src/
Solution
Step 1: Use -S 'TODO' to search string changes
This finds commits adding or removing 'TODO'.
Step 2: Use -- src/ to limit search to the src folder
The double dash -- separates options from path arguments, so -- src/ limits the search to that folder.
Step 3: Check other options for syntax correctness
src/ alone without -- is invalid here; --path is not a git log option; --S is invalid (uppercase S must be after git log).
Final Answer:
git log -S 'TODO' -- src/ -> Option B
Quick Check:
Use -- before path to limit git log search = C [OK]
Hint: Use -- before folder path to limit git log search [OK]