# git locate

17 messages from 2010-01-20 to 2010-06-03. Participants: John Tapsell, Johannes Schindelin, Jakub Narebski, SungHyun Nam, Michael J Gruber, Štěpán Němec, Sverre Rabbelier, Bruce Stephens, Matthieu Moy, Nguyen Thai Ngoc Duy, Clemens Buchacher.
Thread: https://gitlist.dev/t/22296

## John Tapsell, 2010-01-20 01:17

Subject: git locate
Message-ID: <43d8ce651001191717l58d10919j691f4e5b056fe9b5@mail.gmail.com>
URL: https://gitlist.dev/e/43d8ce651001191717l58d10919j691f4e5b056fe9b5%40mail.gmail.com

```
Hey all,

  Could we add a:  git locate <filename>       or git find <filename>
 that is just an alias to "git ls-files | grep filename" ?

Reasons:

1) git ls-files   does not autocomplete, since it's an low-level
plumbing command
2) It's nice having shell equivalents - e.g.  git grep etc

John

```

## Johannes Schindelin, 2010-01-20 01:24

Subject: Re: git locate
Message-ID: <alpine.DEB.1.00.1001200224270.4985@pacific.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.1001200224270.4985%40pacific.mpi-cbg.de
In-Reply-To: <43d8ce651001191717l58d10919j691f4e5b056fe9b5@mail.gmail.com>

```
Hi,

On Wed, 20 Jan 2010, John Tapsell wrote:

>   Could we add a:  git locate <filename>       or git find <filename>

How about "git ls-files \*<filename>"?

Ciao,
Dscho

```

## Jakub Narebski, 2010-01-20 02:14

Subject: Re: git locate
Message-ID: <m3zl49bk0o.fsf@localhost.localdomain>
URL: https://gitlist.dev/e/m3zl49bk0o.fsf%40localhost.localdomain
In-Reply-To: <alpine.DEB.1.00.1001200224270.4985@pacific.mpi-cbg.de>

```
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> On Wed, 20 Jan 2010, John Tapsell wrote:
> 
> >   Could we add a:  git locate <filename>       or git find <filename>
> 
> How about "git ls-files \*<filename>"?

Or "git ls-files '*filename'...

... but how to make an (git) alias for this?

-- 
Jakub Narebski
Poland
ShadeHawk on #git

```

## Johannes Schindelin, 2010-01-20 09:32

Subject: Re: git locate
Message-ID: <alpine.DEB.1.00.1001201021060.31129@intel-tinevez-2-302>
URL: https://gitlist.dev/e/alpine.DEB.1.00.1001201021060.31129%40intel-tinevez-2-302
In-Reply-To: <m3zl49bk0o.fsf@localhost.localdomain>

```
Hi,

On Tue, 19 Jan 2010, Jakub Narebski wrote:

> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> > On Wed, 20 Jan 2010, John Tapsell wrote:
> > 
> > >   Could we add a:  git locate <filename>       or git find <filename>
> > 
> > How about "git ls-files \*<filename>"?
> 
> Or "git ls-files '*filename'...
> 
> ... but how to make an (git) alias for this?

Add something like this to your $HOME/.gitconfig:

[alias]
        locate = !sh -c 'git ls-files "\\*$1"' -

Ciao,
Dscho

```

## Jakub Narebski, 2010-01-20 10:06

Subject: Re: git locate
Message-ID: <201001201106.20739.jnareb@gmail.com>
URL: https://gitlist.dev/e/201001201106.20739.jnareb%40gmail.com
In-Reply-To: <alpine.DEB.1.00.1001201021060.31129@intel-tinevez-2-302>

```
On Wed, 20 Jan 2010, Johannes Schindelin wrote:
> On Tue, 19 Jan 2010, Jakub Narebski wrote:
>> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>>> On Wed, 20 Jan 2010, John Tapsell wrote:
>>> 
>>>>   Could we add a:  git locate <filename>       or git find <filename>
>>> 
>>> How about "git ls-files \*<filename>"?
>> 
>> Or "git ls-files '*filename'...
>> 
>> ... but how to make an (git) alias for this?
> 
> Add something like this to your $HOME/.gitconfig:
> 
> [alias]
>         locate = !sh -c 'git ls-files "\\*$1"' -

Thanks a lot, Dscho!


I think it would be nice to have this trick 

  alias.<cmd> = !sh -c '<commands with $1, $@, $#>' -

described in git-config (alias) documentation.  Unfortunately I don't
understand this trick well enough to do it myself...

-- 
Jakub Narebski
Poland

```

## John Tapsell, 2010-01-20 11:07

Subject: Re: git locate
Message-ID: <43d8ce651001200307r651a6a54ib298c4b708016b11@mail.gmail.com>
URL: https://gitlist.dev/e/43d8ce651001200307r651a6a54ib298c4b708016b11%40mail.gmail.com
In-Reply-To: <201001201106.20739.jnareb@gmail.com>

```
2010/1/20 Jakub Narebski <jnareb@gmail.com>:
> On Wed, 20 Jan 2010, Johannes Schindelin wrote:
>> On Tue, 19 Jan 2010, Jakub Narebski wrote:
>>> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>>>> On Wed, 20 Jan 2010, John Tapsell wrote:
>>>>
>>>>>   Could we add a:  git locate <filename>       or git find <filename>
>>>>
>>>> How about "git ls-files \*<filename>"?
>>>
>>> Or "git ls-files '*filename'...
>>>
>>> ... but how to make an (git) alias for this?
>>
>> Add something like this to your $HOME/.gitconfig:
>>
>> [alias]
>>         locate = !sh -c 'git ls-files "\\*$1"' -
>

I think having this alias by default would be very nice though - it's
pretty common to locate/find files, and it's nice to have unixy
equivalents in git.

If this really isn't wanted, then perhaps the ls-files command should
be bash auto-completed?

Thanks!

John

```

## Johannes Schindelin, 2010-01-20 11:43

Subject: Re: git locate
Message-ID: <alpine.DEB.1.00.1001201238370.31129@intel-tinevez-2-302>
URL: https://gitlist.dev/e/alpine.DEB.1.00.1001201238370.31129%40intel-tinevez-2-302
In-Reply-To: <201001201106.20739.jnareb@gmail.com>

```
Hi,

On Wed, 20 Jan 2010, Jakub Narebski wrote:

> On Wed, 20 Jan 2010, Johannes Schindelin wrote:
> > On Tue, 19 Jan 2010, Jakub Narebski wrote:
> >> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> >>> On Wed, 20 Jan 2010, John Tapsell wrote:
> >>> 
> >>>>   Could we add a:  git locate <filename>       or git find <filename>
> >>> 
> >>> How about "git ls-files \*<filename>"?
> >> 
> >> Or "git ls-files '*filename'...
> >> 
> >> ... but how to make an (git) alias for this?
> > 
> > Add something like this to your $HOME/.gitconfig:
> > 
> > [alias]
> >         locate = !sh -c 'git ls-files "\\*$1"' -
> 
> Thanks a lot, Dscho!
> 
> 
> I think it would be nice to have this trick 
> 
>   alias.<cmd> = !sh -c '<commands with $1, $@, $#>' -

Heh.  I initially read @$^&*#^&*@#$.

> described in git-config (alias) documentation.  Unfortunately I don't 
> understand this trick well enough to do it myself...

I tried to explain things properly in

http://git.wiki.kernel.org/index.php/Aliases#Advanced_aliases_with_arguments

Ciao,
Dscho

```

## SungHyun Nam, 2010-01-21 00:11

Subject: Re: git locate
Message-ID: <4B579BA8.8050000@gmail.com>
URL: https://gitlist.dev/e/4B579BA8.8050000%40gmail.com
In-Reply-To: <alpine.DEB.1.00.1001201021060.31129@intel-tinevez-2-302>

```
Hello,

Johannes Schindelin wrote:
>
> On Tue, 19 Jan 2010, Jakub Narebski wrote:
>
>> Johannes Schindelin<Johannes.Schindelin@gmx.de>  writes:
>>
>>> On Wed, 20 Jan 2010, John Tapsell wrote:
>>>
>>>>    Could we add a:  git locate<filename>        or git find<filename>
>>>
>>> How about "git ls-files \*<filename>"?
>>
>> Or "git ls-files '*filename'...
>>
>> ... but how to make an (git) alias for this?
>
> Add something like this to your $HOME/.gitconfig:
>
> [alias]
>          locate = !sh -c 'git ls-files "\\*$1"' -

The alias 'git locate' and the command 'git ls-files' runs
differently if I run them in a subdirectory.
Is it expected?

[master] ~/srcs/git[299]$ git locate urls.txt
Documentation/urls.txt
[master] ~/srcs/git[300]$ git ls-files '*urls.txt'
Documentation/urls.txt
[master] ~/srcs/git[301]$ cd t
[master] ~/srcs/git/t[302]$ git locate urls.txt
Documentation/urls.txt
[master] ~/srcs/git/t[303]$ git ls-files '*urls.txt'
[master] ~/srcs/git/t[304]$

Thanks,
namsh

```

## Michael J Gruber, 2010-01-21 09:42

Subject: Re: git locate
Message-ID: <4B58217B.4040205@drmicha.warpmail.net>
URL: https://gitlist.dev/e/4B58217B.4040205%40drmicha.warpmail.net
In-Reply-To: <4B579BA8.8050000@gmail.com>

```
SungHyun Nam venit, vidit, dixit 21.01.2010 01:11:
> Hello,
> 
> Johannes Schindelin wrote:
>>
>> On Tue, 19 Jan 2010, Jakub Narebski wrote:
>>
>>> Johannes Schindelin<Johannes.Schindelin@gmx.de>  writes:
>>>
>>>> On Wed, 20 Jan 2010, John Tapsell wrote:
>>>>
>>>>>    Could we add a:  git locate<filename>        or git find<filename>
>>>>
>>>> How about "git ls-files \*<filename>"?
>>>
>>> Or "git ls-files '*filename'...
>>>
>>> ... but how to make an (git) alias for this?
>>
>> Add something like this to your $HOME/.gitconfig:
>>
>> [alias]
>>          locate = !sh -c 'git ls-files "\\*$1"' -
> 
> The alias 'git locate' and the command 'git ls-files' runs
> differently if I run them in a subdirectory.
> Is it expected?
> 
> [master] ~/srcs/git[299]$ git locate urls.txt
> Documentation/urls.txt
> [master] ~/srcs/git[300]$ git ls-files '*urls.txt'
> Documentation/urls.txt
> [master] ~/srcs/git[301]$ cd t
> [master] ~/srcs/git/t[302]$ git locate urls.txt
> Documentation/urls.txt
> [master] ~/srcs/git/t[303]$ git ls-files '*urls.txt'
> [master] ~/srcs/git/t[304]$

Yes, aliases with "!" are executed from the root of the worktree,
ls-files from the current wd.

Michael

```

## Štěpán Němec, 2010-01-21 09:51

Subject: Re: git locate
Message-ID: <20100121095137.GB7370@headley>
URL: https://gitlist.dev/e/20100121095137.GB7370%40headley
In-Reply-To: <4B579BA8.8050000@gmail.com>

```
On Thu, Jan 21, 2010 at 09:11:20AM +0900, SungHyun Nam wrote:
> Hello,
> 
> Johannes Schindelin wrote:
> >
> >On Tue, 19 Jan 2010, Jakub Narebski wrote:
> >
> >>Johannes Schindelin<Johannes.Schindelin@gmx.de>  writes:
> >>
> >>>On Wed, 20 Jan 2010, John Tapsell wrote:
> >>>
> >>>>   Could we add a:  git locate<filename>        or git find<filename>
> >>>
> >>>How about "git ls-files \*<filename>"?
> >>
> >>Or "git ls-files '*filename'...
> >>
> >>... but how to make an (git) alias for this?
> >
> >Add something like this to your $HOME/.gitconfig:
> >
> >[alias]
> >         locate = !sh -c 'git ls-files "\\*$1"' -
> 
> The alias 'git locate' and the command 'git ls-files' runs
> differently if I run them in a subdirectory.
> Is it expected?
> 
> [master] ~/srcs/git[299]$ git locate urls.txt
> Documentation/urls.txt
> [master] ~/srcs/git[300]$ git ls-files '*urls.txt'
> Documentation/urls.txt
> [master] ~/srcs/git[301]$ cd t
> [master] ~/srcs/git/t[302]$ git locate urls.txt
> Documentation/urls.txt
> [master] ~/srcs/git/t[303]$ git ls-files '*urls.txt'
> [master] ~/srcs/git/t[304]$

Yeah, as stated in another part of the Wiki page Dscho referred to
(namely the "Serve repo on the spot" section):

"It makes use of the fact that (currently, as of git 1.5.6.1) non-git
alias are executed from the top-level dir of a repo."

("non-git" == those starting with "!", which is the case here)


    Štěpán

```

## Sverre Rabbelier, 2010-02-15 13:20

Subject: Re: git locate
Message-ID: <fabb9a1e1002150520v29cf8d59ke27cde3e9697b011@mail.gmail.com>
URL: https://gitlist.dev/e/fabb9a1e1002150520v29cf8d59ke27cde3e9697b011%40mail.gmail.com
In-Reply-To: <4B579BA8.8050000@gmail.com>

```
Heya,

On Thu, Jan 21, 2010 at 01:11, SungHyun Nam <goweol@gmail.com> wrote:
> The alias 'git locate' and the command 'git ls-files' runs
> differently if I run them in a subdirectory.
> Is it expected?

I just ran into this (I wanted to alias 'git find' but to me the 'run
ls-files from cwd' is desirable. Also, I prefer to have a trailing
glob as well, so I added one :). An easy solution is to drop
'git-find' in your path somewhere:

sverre@laptop-sverre:~/bin$ cat git-find
#!/bin/bash

git ls-files "*$1*"

-- 
Cheers,

Sverre Rabbelier

```

## John Tapsell, 2010-06-02 05:00

Subject: Re: git locate
Message-ID: <AANLkTim6cLkr5BFTRTh2nZGwsfVgHZi3M-b9IER8dHf3@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTim6cLkr5BFTRTh2nZGwsfVgHZi3M-b9IER8dHf3%40mail.gmail.com
In-Reply-To: <fabb9a1e1002150520v29cf8d59ke27cde3e9697b011@mail.gmail.com>

```
On 15 February 2010 22:20, Sverre Rabbelier <srabbelier@gmail.com> wrote:
> Heya,
>
> On Thu, Jan 21, 2010 at 01:11, SungHyun Nam <goweol@gmail.com> wrote:
>> The alias 'git locate' and the command 'git ls-files' runs
>> differently if I run them in a subdirectory.
>> Is it expected?
>
> I just ran into this (I wanted to alias 'git find' but to me the 'run
> ls-files from cwd' is desirable. Also, I prefer to have a trailing
> glob as well, so I added one :). An easy solution is to drop
> 'git-find' in your path somewhere:

I have finally settled on:

[alias]
    locate = !sh -c 'git ls-files | grep --color=auto "$1"' -

This acts as if there is a leading and trailing wildcard, and also
colors the output nicely.

Can we add this as default please?  There didn't seem to be any
resistance in this thread to making it default, just that nobody did
it :)

John

```

## John Tapsell, 2010-06-02 10:02

Subject: Re: git locate
Message-ID: <AANLkTil38OLw3J6ZPvv2wNu98QuTXJKtNwRZP0NDZPWn@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTil38OLw3J6ZPvv2wNu98QuTXJKtNwRZP0NDZPWn%40mail.gmail.com
In-Reply-To: <AANLkTim6cLkr5BFTRTh2nZGwsfVgHZi3M-b9IER8dHf3@mail.gmail.com>

```
On 2 June 2010 14:00, John Tapsell <johnflux@gmail.com> wrote:
> On 15 February 2010 22:20, Sverre Rabbelier <srabbelier@gmail.com> wrote:
>> Heya,
>>
>> On Thu, Jan 21, 2010 at 01:11, SungHyun Nam <goweol@gmail.com> wrote:
>>> The alias 'git locate' and the command 'git ls-files' runs
>>> differently if I run them in a subdirectory.
>>> Is it expected?
>>
>> I just ran into this (I wanted to alias 'git find' but to me the 'run
>> ls-files from cwd' is desirable. Also, I prefer to have a trailing
>> glob as well, so I added one :). An easy solution is to drop
>> 'git-find' in your path somewhere:
>
> I have finally settled on:
>
> [alias]
>    locate = !sh -c 'git ls-files | grep --color=auto "$1"' -


Actually could someone help me with this.. the trouble is that this
returns paths relative to the root.

Can I get it to find all the files, but relative to where I am now?

John

```

## Bruce Stephens, 2010-06-02 10:23

Subject: Re: git locate
Message-ID: <80y6ex3f8b.fsf@tiny.isode.net>
URL: https://gitlist.dev/e/80y6ex3f8b.fsf%40tiny.isode.net
In-Reply-To: <AANLkTil38OLw3J6ZPvv2wNu98QuTXJKtNwRZP0NDZPWn@mail.gmail.com>

```
John Tapsell <johnflux@gmail.com> writes:

[...]

> Actually could someone help me with this.. the trouble is that this
> returns paths relative to the root.
>
> Can I get it to find all the files, but relative to where I am now?

Something like this is probably part of the answer, which allows an
alias like this to work:

	locate = !cd $GIT_CWD && sh -c 'git ls-files "*$1*"' -

That doesn't give you all the files (just those below where you are).

diff --git a/git.c b/git.c
index 99f0363..81c877b 100644
--- a/git.c
+++ b/git.c
@@ -178,6 +178,10 @@ static int handle_alias(int *argcp, const char ***argv)
                        }
                        trace_printf("trace: alias to shell cmd: %s => %s\n",
                                     alias_command, alias_string + 1);
+                       if (!subdir || !*subdir)
+                         setenv("GIT_CWD", "./", 1);
+                       else
+                         setenv("GIT_CWD", subdir, 1);
                        ret = system(alias_string + 1);
                        if (ret >= 0 && WIFEXITED(ret) &&
                            WEXITSTATUS(ret) != 127)

```

## Matthieu Moy, 2010-06-02 11:27

Subject: Re: git locate
Message-ID: <vpqwruhwu6f.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqwruhwu6f.fsf%40bauges.imag.fr
In-Reply-To: <80y6ex3f8b.fsf@tiny.isode.net>

```
Bruce Stephens <bruce.stephens@isode.com> writes:

> John Tapsell <johnflux@gmail.com> writes:
>
> [...]
>
>> Actually could someone help me with this.. the trouble is that this
>> returns paths relative to the root.
>>
>> Can I get it to find all the files, but relative to where I am now?
>
> Something like this is probably part of the answer, which allows an
> alias like this to work:
>
> 	locate = !cd $GIT_CWD && sh -c 'git ls-files "*$1*"' -

There's a patch pending to do more or less the same thing:

  http://thread.gmane.org/gmane.comp.version-control.git/146360/focus=146450

Read Junio's reply there:

  http://thread.gmane.org/gmane.comp.version-control.git/146360/focus=146450

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

```

## Nguyen Thai Ngoc Duy, 2010-06-02 11:29

Subject: Re: git locate
Message-ID: <AANLkTinBwk_l-prWXHiAE8UoSMaJMebHm5Y7J8TOScYR@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTinBwk_l-prWXHiAE8UoSMaJMebHm5Y7J8TOScYR%40mail.gmail.com
In-Reply-To: <AANLkTil38OLw3J6ZPvv2wNu98QuTXJKtNwRZP0NDZPWn@mail.gmail.com>

```
On Wed, Jun 2, 2010 at 12:02 PM, John Tapsell <johnflux@gmail.com> wrote:
> On 2 June 2010 14:00, John Tapsell <johnflux@gmail.com> wrote:
>> On 15 February 2010 22:20, Sverre Rabbelier <srabbelier@gmail.com> wrote:
>>> Heya,
>>>
>>> On Thu, Jan 21, 2010 at 01:11, SungHyun Nam <goweol@gmail.com> wrote:
>>>> The alias 'git locate' and the command 'git ls-files' runs
>>>> differently if I run them in a subdirectory.
>>>> Is it expected?
>>>
>>> I just ran into this (I wanted to alias 'git find' but to me the 'run
>>> ls-files from cwd' is desirable. Also, I prefer to have a trailing
>>> glob as well, so I added one :). An easy solution is to drop
>>> 'git-find' in your path somewhere:
>>
>> I have finally settled on:
>>
>> [alias]
>>    locate = !sh -c 'git ls-files | grep --color=auto "$1"' -
>
>
> Actually could someone help me with this.. the trouble is that this
> returns paths relative to the root.
>
> Can I get it to find all the files, but relative to where I am now?

Make it a git command, not an alias. You'll then be fine. put
git-locate somewhere in your $PATH

--<--
#!/bin/sh
git ls-files | grep --color=auto "$1"
--<--

Of course you need to chmod u+x for it.
-- 
Duy

```

## Clemens Buchacher, 2010-06-03 13:39

Subject: Re: git locate
Message-ID: <20100603133950.GA30826@localhost>
URL: https://gitlist.dev/e/20100603133950.GA30826%40localhost
In-Reply-To: <80y6ex3f8b.fsf@tiny.isode.net>

```
On Wed, Jun 02, 2010 at 11:23:32AM +0100, Bruce Stephens wrote:

> Something like this is probably part of the answer, which allows an
> alias like this to work:
> 
> 	locate = !cd $GIT_CWD && sh -c 'git ls-files "*$1*"' -
> 
> That doesn't give you all the files (just those below where you are).

Once relative path support for ls-files is done (patch pending) you
can do git ls-files $(git rev-parse --show-cdup).

Clemens

```
