1

I'm searching for a commit where a string first introduced in a file . This commit can be in master or any branch .

I'm searching for a commit where string "public static String BUILD = "0829_12"" was introduced in file 'version.java'

The prbolem is that the branch where this commit occurred was deleted.

How can I search for that ?

nadavgam
  • 2,014
  • 5
  • 20
  • 48
  • 2
    Note that when using these -S and -G `git log` options and you want to find where it *first occurred*, just take the last one shown (since they're sorted into reverse date order by default). Use `--branches` or `--all` to search from all branches or all references. – torek Mar 12 '17 at 12:26
  • I forgot to add that i need to search commits of deleted branch also – nadavgam Mar 12 '17 at 12:43
  • 1
    If the branch name is gone, the commits are either reachable by another name, or also gone. If they are reachable by tag or remote-tracking-branch name, `--all` will find them. If they are truly gone, they're *gone*. – torek Mar 12 '17 at 13:07
  • See http://stackoverflow.com/questions/1337320/how-to-grep-git-commit-diffs-or-contents-for-a-certain-word for searching. But see earlier comment for "gone". – torek Mar 12 '17 at 13:10

1 Answers1

1

If the commit has not been removed, you can run:

# If you know where the commit lives
git checkout branch_where_the_commit_lives
git log -S 'public static String BUILD = "0829_12"' -p path/to/version.java

# If you don't know, you should add --all to the previous command and run it from any branch
git log --all -S 'public static String BUILD = "0829_12"' -p path/to/version.java
smarber
  • 4,829
  • 7
  • 37
  • 78