13

There is a file in my git repo which was changed a lot of times. I want to know the revisions in which a specific text was present in this file.

Is there a git command to get this information?

Something like:

git find "specific_text" -- /frequently/modified/file 

Which would output a list of commits.

2

2 Answers 2

15

git grep <pattern> will search only one commit.

If you want to search all of git's history, use one of the pickaxe options :

git log -G "specific_text" -- frequently/modified/file # or : git log -S "specific_text" -- frequently/modified/file 

The difference between the two is explained in the docs :

  • -G will list all commits where specific_text appears in the diff,
  • -S will only list commits where the count of specific_text changes, e.g : the commit where this text appears, the commit where it gets deleted, but not a commit which just moves it around, without adding or removing an instance.

You can also add -p if you want to see the diff itself :

git log -p -S "specific_text" -- frequently/modified/file 
Sign up to request clarification or add additional context in comments.

Comments

2

You can do

git log -G 'specific text' -- /frequently/modified/file 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.