0
0
Gitdevops~20 mins

Searching history with git log -S - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Git Log Search Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What does the command git log -S'fixBug' do?

Consider the command git log -S'fixBug'. What is the output or effect of running this command in a git repository?

Git
git log -S'fixBug'
ADisplays commits that modified files named 'fixBug'.
BShows commits that added or removed the string 'fixBug' anywhere in the code.
CLists commits that contain the word 'fixBug' in their commit message only.
DSearches for commits that changed the author name to 'fixBug'.
Attempts:
2 left
💡 Hint

Think about what the -S option searches for in the commit history.

Best Practice
intermediate
2:00remaining
Which command helps find commits that introduced or removed a function named calculateSum?

You want to find commits where the function calculateSum was added or removed in your code. Which git command is best suited for this?

Agit log -S'calculateSum'
Bgit log --grep='calculateSum'
Cgit log --author='calculateSum'
Dgit log --name-only | grep 'calculateSum'
Attempts:
2 left
💡 Hint

Remember, -S searches code changes, while --grep searches commit messages.

Troubleshoot
advanced
2:00remaining
Why does git log -S'init' show no commits even though the string exists in the code?

You run git log -S'init' but it returns no commits, even though the string 'init' is present in your current code files. What is the most likely reason?

AThe string 'init' was never added or removed in any commit; it was always present.
BThe repository is corrupted and cannot search history.
CThe command requires <code>--all</code> to search all branches.
DThe string 'init' is too short and ignored by git log.
Attempts:
2 left
💡 Hint

Think about what -S actually searches for in commits.

🧠 Conceptual
advanced
2:00remaining
What is the difference between git log -S and git log -G?

Both git log -S and git log -G search commit history. What is the key difference between them?

A<code>-S</code> searches author names; <code>-G</code> searches file names.
B<code>-S</code> searches commit messages; <code>-G</code> searches code changes.
C<code>-S</code> searches only the latest commit; <code>-G</code> searches all commits.
D<code>-S</code> searches for changes in the number of occurrences of a string; <code>-G</code> searches for commits matching a regex pattern.
Attempts:
2 left
💡 Hint

Consider how -S and -G treat the search string.

🔀 Workflow
expert
3:00remaining
How to find the first commit that introduced the string TODO using git log -S?

You want to find the very first commit in your repository history that introduced the string TODO. Which sequence of commands or options will help you achieve this?

Agit log -S'TODO' --reverse
Bgit log -S'TODO' --reverse --ancestry-path --all
Cgit log -S'TODO' --all --reverse --max-count=1
Dgit log -S'TODO' --max-count=1
Attempts:
2 left
💡 Hint

Think about how to reverse the order and limit results to find the first commit.