4

I need to search a word in all files of my repository and in all version of all files. This because I don't know when, but there is no more a piece of code in one of my file and I want to know when was deleted and recover it.

1

2 Answers 2

2

I don't know if this was what you meant, but if you want to find all commits where commit message contains given word, use

$ git log --grep=word 

If you want to find all commits where "word" was added or removed in the file contents (to be more exact: where number of occurences of "word" changed), i.e. search the commit contents, use so called 'pickaxe' search with

$ git log -Sword 

Good Luck :)

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, I will try. The second (-S) is my necessity.
I actually got this off another question on stackoverflow, all I did was search google for "how to grep git commits", or well, "how to search git commits"
Anyway, I'm glad to help
1

What you're looking to do here is grep (documentation on git-grep) through the history of all revisions in the repository:

$ git grep <your_search_term> $(git rev-list --all) 

Where <your_search_term> is a regex pattern.

The output will include all of the commits including your found text/expression.

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.