git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Most recent revision that contains a string
@ 2016-08-20 21:41 Nikolaus Rath
  2016-08-21  1:30 ` Josh Triplett
  2016-08-21  2:46 ` Eric Wong
  0 siblings, 2 replies; 7+ messages in thread
From: Nikolaus Rath @ 2016-08-20 21:41 UTC (permalink / raw)
  To: git

Hello,

What's the easiest way to find the most recent revision (of any file in
the repository, including those that have been deleted in the current
HEAD) that contains a given string?

I was hoping that "git grep" would do this (like in Mercurial), but as
far as I can tell it only greps through the working copy. Or is there a
trick that I'm missing?

Thanks,
-Nikolaus

-- 
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             »Time flies like an arrow, fruit flies like a Banana.«

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Most recent revision that contains a string
  2016-08-20 21:41 Most recent revision that contains a string Nikolaus Rath
@ 2016-08-21  1:30 ` Josh Triplett
  2016-08-21  8:13   ` Andreas Schwab
  2016-08-21  2:46 ` Eric Wong
  1 sibling, 1 reply; 7+ messages in thread
From: Josh Triplett @ 2016-08-21  1:30 UTC (permalink / raw)
  To: git

On Sat, Aug 20, 2016 at 02:41:35PM -0700, Nikolaus Rath wrote:
> Hello,
> 
> What's the easiest way to find the most recent revision (of any file in
> the repository, including those that have been deleted in the current
> HEAD) that contains a given string?
> 
> I was hoping that "git grep" would do this (like in Mercurial), but as
> far as I can tell it only greps through the working copy. Or is there a
> trick that I'm missing?

git grep can search through any arbitrary blob, tree, commit, or tag.
So you can search through HEAD~10, or HEAD~10:path/to/directory, or
HEAD~10:path/to/file.  (You can also search the index with --cached, and
various other options exist as well.)

If you want to find a change that introduces or removes a particular
string, you could use "git log -S".  That doesn't allow regexes, but it
might do what you want.  "git grep" will find occurrences of the string
in the current version, and if it has been removed, "git log -S" will
find the removal.

I don't know of any way to do that in one file-oriented step, searching
backward through the first occurrence of every path, including deleted
paths.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Most recent revision that contains a string
  2016-08-20 21:41 Most recent revision that contains a string Nikolaus Rath
  2016-08-21  1:30 ` Josh Triplett
@ 2016-08-21  2:46 ` Eric Wong
  2016-08-22 18:06   ` Nikolaus Rath
  1 sibling, 1 reply; 7+ messages in thread
From: Eric Wong @ 2016-08-21  2:46 UTC (permalink / raw)
  To: Nikolaus Rath; +Cc: git

Nikolaus Rath <Nikolaus@rath.org> wrote:
> What's the easiest way to find the most recent revision (of any file in
> the repository, including those that have been deleted in the current
> HEAD) that contains a given string?

I normally do something like:

	git log -r --raw -p -SSTRING
	git log -r --raw -p -GREGEXP

You can also add --diff-filter=D to filter only on deletes.


Btw, please don't set these headers on kernel.org lists:

	Mail-Copies-To: never
	Mail-Followup-To: git@vger.kernel.org

Like any mail server, vger fails from time-to-time and
reply-to-all prevents it from being a single point of failure.
Thanks.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Most recent revision that contains a string
  2016-08-21  1:30 ` Josh Triplett
@ 2016-08-21  8:13   ` Andreas Schwab
  2016-08-21  8:48     ` Josh Triplett
  0 siblings, 1 reply; 7+ messages in thread
From: Andreas Schwab @ 2016-08-21  8:13 UTC (permalink / raw)
  To: Josh Triplett; +Cc: git

On Aug 20 2016, Josh Triplett <josh@joshtriplett.org> wrote:

> If you want to find a change that introduces or removes a particular
> string, you could use "git log -S".  That doesn't allow regexes,

It does, actually, see --pickaxe-regex.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Most recent revision that contains a string
  2016-08-21  8:13   ` Andreas Schwab
@ 2016-08-21  8:48     ` Josh Triplett
  0 siblings, 0 replies; 7+ messages in thread
From: Josh Triplett @ 2016-08-21  8:48 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: git

On Sun, Aug 21, 2016 at 10:13:33AM +0200, Andreas Schwab wrote:
> On Aug 20 2016, Josh Triplett <josh@joshtriplett.org> wrote:
> > If you want to find a change that introduces or removes a particular
> > string, you could use "git log -S".  That doesn't allow regexes,
> 
> It does, actually, see --pickaxe-regex.

Thanks; I found that after looking up "git log -G", which Eric Wong
mentioned in another reply.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Most recent revision that contains a string
  2016-08-21  2:46 ` Eric Wong
@ 2016-08-22 18:06   ` Nikolaus Rath
  2016-08-23 19:36     ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Nikolaus Rath @ 2016-08-22 18:06 UTC (permalink / raw)
  To: Eric Wong; +Cc: git

On Aug 21 2016, Eric Wong <e@80x24.org> wrote:
> Nikolaus Rath <Nikolaus@rath.org> wrote:
>> What's the easiest way to find the most recent revision (of any file in
>> the repository, including those that have been deleted in the current
>> HEAD) that contains a given string?
>
> I normally do something like:
>
> 	git log -r --raw -p -SSTRING
> 	git log -r --raw -p -GREGEXP
>
> You can also add --diff-filter=D to filter only on deletes.

Great, thanks!

> Btw, please don't set these headers on kernel.org lists:
>
> 	Mail-Copies-To: never
> 	Mail-Followup-To: git@vger.kernel.org
>
> Like any mail server, vger fails from time-to-time and
> reply-to-all prevents it from being a single point of failure.

Huh? If the list-server fails only I will receive the message so it's
still lost for everyone else. But I am more than happy to take this
little risk if it saves me from the nuisance of getting duplicate
responses.

Best,
-Nikolaus

-- 
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             »Time flies like an arrow, fruit flies like a Banana.«

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Most recent revision that contains a string
  2016-08-22 18:06   ` Nikolaus Rath
@ 2016-08-23 19:36     ` Junio C Hamano
  0 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2016-08-23 19:36 UTC (permalink / raw)
  To: Nikolaus Rath; +Cc: git, Eric Wong

Nikolaus Rath <Nikolaus@rath.org> writes:

>> Btw, please don't set these headers on kernel.org lists:
>>
>> 	Mail-Copies-To: never
>> 	Mail-Followup-To: git@vger.kernel.org
>>
>> Like any mail server, vger fails from time-to-time and
>> reply-to-all prevents it from being a single point of failure.
>
> Huh? If the list-server fails only I will receive the message so it's
> still lost for everyone else. But I am more than happy to take this
> little risk if it saves me from the nuisance of getting duplicate
> responses.

On a mailing list, your readers' time is more valuable than yours,
simply because there are a lot more of them.

I am typing this message ONLY because I want to talk to YOU, and I
want your address to be on its To: field, with Eric and the list on
Cc: field.  The recipients can prioritize their incoming messages by
reading what's addressed directly to them first and when they have
leftover time they can read ones that they are CC'ed, but because
you used Mail-Followup-To: I had to correct the headers manually,
which means you stole time from me.  And if I didn't then your
Mail-Followup-to: would have stolen time from the other recipients.

Please don't use it on this list.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-08-23 19:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-20 21:41 Most recent revision that contains a string Nikolaus Rath
2016-08-21  1:30 ` Josh Triplett
2016-08-21  8:13   ` Andreas Schwab
2016-08-21  8:48     ` Josh Triplett
2016-08-21  2:46 ` Eric Wong
2016-08-22 18:06   ` Nikolaus Rath
2016-08-23 19:36     ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).