git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josh Triplett <josh@joshtriplett.org>
To: git@vger.kernel.org
Subject: Re: Most recent revision that contains a string
Date: Sat, 20 Aug 2016 18:30:42 -0700	[thread overview]
Message-ID: <20160821013040.4sfmg2v7rcovxxmb@x> (raw)
In-Reply-To: <87d1l3ce40.fsf@thinkpad.rath.org>

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.

  reply	other threads:[~2016-08-21  1:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-20 21:41 Most recent revision that contains a string Nikolaus Rath
2016-08-21  1:30 ` Josh Triplett [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160821013040.4sfmg2v7rcovxxmb@x \
    --to=josh@joshtriplett.org \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).