0
0
Gitdevops~20 mins

Searching history with git log -S - Mini Project: Build & Apply

Choose your learning style9 modes available
Searching History with git log -S
📖 Scenario: You are working on a project with a Git repository. You want to find all commits where a specific word or phrase was added or removed in the code. This helps you track when a feature or bug was introduced.
🎯 Goal: Learn how to use git log -S to search commit history for changes that add or remove a specific string.
📋 What You'll Learn
A Git repository with at least 3 commits
A file named app.txt tracked by Git
Use git log -S to search commit history
💡 Why This Matters
🌍 Real World
Developers often need to find when a bug or feature was introduced by searching commit history for specific code changes.
💼 Career
Knowing how to use <code>git log -S</code> is useful for debugging, code reviews, and understanding project history in software development roles.
Progress0 / 4 steps
1
Create a Git repository and add a file
Initialize a Git repository in the current folder by running git init. Then create a file named app.txt with the exact content Hello World. Add and commit this file with the message Initial commit.
Git
Need a hint?

Use git init to start a repo. Use echo to create the file. Then add and commit.

2
Make a second commit changing the file
Change the content of app.txt to Hello Git. Then add and commit this change with the message Update greeting.
Git
Need a hint?

Use echo again to overwrite the file. Then add and commit.

3
Make a third commit adding a new line
Append the line Goodbye to app.txt. Then add and commit this change with the message Add farewell.
Git
Need a hint?

Use >> to append text to the file. Then add and commit.

4
Search commits that added or removed the word 'Goodbye'
Run the command git log -S Goodbye --oneline to find commits where the word Goodbye was added or removed. This will show the commit hash and message.
Git
Need a hint?

The -S option searches for commits that add or remove the string. Use --oneline for a short summary.