Robin Green
Robin Green

Reputation: 33033

Search for string in files changed on git branch

I want to search for a string in a file that I have changed on a git branch, but it's in a line that I haven't changed. How can I do that reliably?

Upvotes: 0

Views: 281

Answers (1)

Robin Green
Robin Green

Reputation: 33033

Here's a solution in bash shell (on Windows, make sure you are using "Git bash" or WSL, not "Git CMD").

Let's call the branch you branched off from develop. Replace develop with the name of the actual branch you branched off this branch from, and search_string with your actual search string, below.

git checkout branch_name
git diff --name-only develop... | xargs grep 'search_string'

Note the three dots! This will ignore changes in develop since you branched off, so it will just compare with the commit you branched it off from.

Upvotes: 1

Related Questions