1

We have a zillion branches and someone reverted important changes. Is there a way to find:

  • which (local or remote) branch contains
  • the version of file.js
  • which contains searchString?

I've found answers to how to find a file in multiple branches, or how to find a string in multiple branches. But not how to find the version of a file containing the specified string in multiple branches.

Tamás Polgár
  • 2,082
  • 5
  • 21
  • 48
  • Does this https://stackoverflow.com/questions/372506/how-can-i-search-git-branches-for-a-file-or-directory cover it? – Benjamin W. Apr 24 '19 at 17:54
  • You can probably amend that to use `git log -p --all -- file.js` and search your string in the output, which gets you the proper commit, and then you can use `git branch -a --contains`. There's probably even a way to do it in one go. – Benjamin W. Apr 24 '19 at 17:56
  • Actually, found a duplicate. – Benjamin W. Apr 24 '19 at 17:57
  • 1
    Possible duplicate of [How to find the Git commit that introduced a string in any branch?](https://stackoverflow.com/questions/5816134/how-to-find-the-git-commit-that-introduced-a-string-in-any-branch) – Benjamin W. Apr 24 '19 at 17:57
  • 1
    No, neither are duplicates. The first one is about how to find a specific file, the second is how to find a specific string. But not a specific string in a specific file in any branch. – Tamás Polgár Apr 24 '19 at 19:13

1 Answers1

3

You can combine the two answers from the suggested duplicate questions like this:

git log -S "searchString" --source --all -- file.js

D Malan
  • 10,272
  • 3
  • 25
  • 50