Git: find remote code

It annoys me.

How to find remote code?

I ended up finding where it was created:

$ git log --pretty=oneline -S'some code' 

And that's good enough, but I was also curious to find where it was removed, and there are still no dice.

First, I tried git diff HEAD..HEAD^|grep 'some code' , expanding the range every time until I found the lines in which it was deleted. It's nice, so suppose I found it on the range HEAD^^..HEAD^^^ , then git show HEAD^^^ and git show HEAD^^ with grep , but the code was not found anywhere!

Then I read a little bit of git bisect , and of course it gives me one revision that the culprit should be ... Again, git show rev|grep 'some code' appears empty ...

What? What am I doing wrong?

Thank!

+41
git
06 Oct '09 at 22:53
source share
3 answers

Hmph, works for me:

 $ git init
 Initialized empty Git repository in /Users/pknotz/foo/.git/

 $ echo "Hello"> a

 $ git add a

 $ git commit -am "initial commit"
 [master (root-commit) 7e52a51] initial commit
  1 files changed, 1 insertions (+), 0 deletions (-)
  create mode 100644 a

 $ echo "World" >> a

 $ git commit -am "Be more specific"
 [master 080e9fe] Be more specific
  1 files changed, 1 insertions (+), 0 deletions (-)

 $ echo "Hello"> a

 $ git commit -am "Be less specific"
 [master 00f3fd0] Be less specific
  1 files changed, 0 insertions (+), 1 deletions (-)

 $ cat a
 Hello

 $ git log -SWorld
 commit 00f3fd0134d0d54aafbb9d959666efc5fd492b4f
 Author: Pat Notz <patnotz@gmail.com>
 Date: Tue Oct 6 17:20:48 2009 -0600

     Be less specific

 commit 080e9fe84ff89aab9d9d51fb5d8d59e8f663ee7f
 Author: Pat Notz <patnotz@gmail.com>
 Date: Tue Oct 6 17:20:33 2009 -0600

     Be more specific

Or is that not what you mean?

+31
06 Oct '09 at 23:27
source share

git log -S<string> does the job, but if you need to do more complex searches, you can use git log -G<regex> .

From man :

-G<regex>

Look at the differences, the patch text contains added / deleted lines that correspond to <regex> .

+16
Jun 03 '14 at 9:19
source share

If your repository is on github.com, it has a built-in search function. It responds in ms and also searches in remote code.

0
Jan 10 2018-12-12T00:
source share



All Articles