Reputation: 10015
I have a file which contained some text at some point which was then deleted.
I forgot which exact commit and in what branch it existed.
Is there any way to search all revisions of a file accross all the branches and find a commit where file contains specific text?
Upvotes: 1
Views: 37
Reputation: 4202
For this purpose you can use the -S option to git log:
git log -S'bar' -- foo.rb
This search the text bar
in the file foo.rb
if you want to search through all diffs you can do: git log -G'bar' -- foo.rb
When -S or -G finds a change, show all the changes in that changeset, not just the files that contain the change in .
NOTE: This search is casesensitive.
If you add -i
you can search case insensitive. Making the complete command:
git log -i -S'bar' -- foo.rb
NOTE 2: This searches only in your current branch.
If you want to search accross all branch you should add the --all
flag
Pretend as if all the refs in refs/, along with HEAD, are listed on the command line as .
The complete command will be:
git log --all -i -S'bar' -- foo.rb
The output will be something like this:
$ git log --all -i -S'bar' -- foo.rb
commit 53106e9cd319a2d8f960a3bbf2731acd0699a54f (feature/x)
Author: name <email>
Date: Fri Jan 18 13:59:32 2019 +0100
Added word
Upvotes: 4