# git alias question

8 messages from 2011-12-29 to 2012-01-02. Participants: Michael Horowitz, Miles Bader, Junio C Hamano, Dave Borowitz, David Aguilar, Jakub Narebski.
Thread: https://gitlist.dev/t/29261

## Michael Horowitz, 2011-12-29 01:27

Subject: git alias question
Message-ID: <CAFLRbopjqW7OEWN4kxy+6Gb828h4zBC_h=4WiP-q1__LeezxUw@mail.gmail.com>
URL: https://gitlist.dev/e/CAFLRbopjqW7OEWN4kxy%2B6Gb828h4zBC_h%3D4WiP-q1__LeezxUw%40mail.gmail.com

```
Hello all,

I have been unable to find a solution to this, so I figured I would
post to this list...

I am trying to make an easy command to let me look at the last diff to
a specified file, either plain or with a diff tool, such as vimdiff.
This is the last actual change, not just HEAD^, because the file may
not have changed in many commits.

I was able to make the following 2 aliases, which work perfectly
except for one problem...

ldiff = "!git diff `git rev-list --reverse -n 2 HEAD -- $1` -- $1"
ldifft = "!git difftool `git rev-list --reverse -n 2 HEAD -- $1` -- $1"

The problem is the limitation that shell commands are always executed
at the top-level directory of the repository.  Normally I am in a
deeply nested directory, so if I specify the file name in that
directory, it doesn't work.  Having to specify the full path relative
to the top level makes these aliases more cumbersome to use than their
worth.

Is there a way to get around this, or even a completely different way
to do this that I am missing?  I want to avoid making a completely
separate shell script.

Thanks,

Mike

```

## Miles Bader, 2011-12-29 03:21

Subject: Re: git alias question
Message-ID: <87wr9g2hcd.fsf@catnip.gol.com>
URL: https://gitlist.dev/e/87wr9g2hcd.fsf%40catnip.gol.com
In-Reply-To: <CAFLRbopjqW7OEWN4kxy+6Gb828h4zBC_h=4WiP-q1__LeezxUw@mail.gmail.com>

```
Michael Horowitz <michael.horowitz@ieee.org> writes:
> I was able to make the following 2 aliases, which work perfectly
> except for one problem...
>
> ldiff = "!git diff `git rev-list --reverse -n 2 HEAD -- $1` -- $1"
> ldifft = "!git difftool `git rev-list --reverse -n 2 HEAD -- $1` -- $1"
>
> The problem is the limitation that shell commands are always executed
> at the top-level directory of the repository.

Hmmm, it'd be cool if git exported an environment variable containing
the CWD when it invoked external aliases like this...!

-Miles

-- 
Love is the difficult realization that something other than oneself is real.
[Iris Murdoch]

```

## Junio C Hamano, 2011-12-29 05:32

Subject: Re: git alias question
Message-ID: <7vy5twx7rh.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vy5twx7rh.fsf%40alter.siamese.dyndns.org
In-Reply-To: <87wr9g2hcd.fsf@catnip.gol.com>

```
Miles Bader <miles@gnu.org> writes:

> Michael Horowitz <michael.horowitz@ieee.org> writes:
>> I was able to make the following 2 aliases, which work perfectly
>> except for one problem...
>>
>> ldiff = "!git diff `git rev-list --reverse -n 2 HEAD -- $1` -- $1"
>> ldifft = "!git difftool `git rev-list --reverse -n 2 HEAD -- $1` -- $1"
>>
>> The problem is the limitation that shell commands are always executed
>> at the top-level directory of the repository.
>
> Hmmm, it'd be cool if git exported an environment variable containing
> the CWD when it invoked external aliases like this...!

Yeah, something like GIT_PREFIX environment variable, I guess.

```

## Dave Borowitz, 2011-12-29 17:08

Subject: Re: git alias question
Message-ID: <CAD0k6qTp9sKCb==Jh1vuLuZoxx99Kt2Z=VAbjYbGaUE7nbOxdQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAD0k6qTp9sKCb%3D%3DJh1vuLuZoxx99Kt2Z%3DVAbjYbGaUE7nbOxdQ%40mail.gmail.com
In-Reply-To: <CAFLRbopjqW7OEWN4kxy+6Gb828h4zBC_h=4WiP-q1__LeezxUw@mail.gmail.com>

```
On Wed, Dec 28, 2011 at 17:27, Michael Horowitz
<michael.horowitz@ieee.org> wrote:
> ldiff = "!git diff `git rev-list --reverse -n 2 HEAD -- $1` -- $1"

FWIW, you can also do this as:
  ldiff = log -p -1 --format=format: --

> ldifft = "!git difftool `git rev-list --reverse -n 2 HEAD -- $1` -- $1"

I don't know that you can do something equivalent with difftool. I
suppose you could do the above with "GIT_EXTERNAL_DIFF=<some difftool
wrapper> git ldiff", but that's not very helpful.

```

## David Aguilar, 2011-12-30 01:59

Subject: Re: git alias question
Message-ID: <CAJDDKr5a8TB82h4ULWtamLOVu_4Fv+cGw1YfEL987gM3yM4TMg@mail.gmail.com>
URL: https://gitlist.dev/e/CAJDDKr5a8TB82h4ULWtamLOVu_4Fv%2BcGw1YfEL987gM3yM4TMg%40mail.gmail.com
In-Reply-To: <CAD0k6qTp9sKCb==Jh1vuLuZoxx99Kt2Z=VAbjYbGaUE7nbOxdQ@mail.gmail.com>

```
On Thu, Dec 29, 2011 at 9:08 AM, Dave Borowitz <dborowitz@google.com> wrote:
> On Wed, Dec 28, 2011 at 17:27, Michael Horowitz
> <michael.horowitz@ieee.org> wrote:
>> ldiff = "!git diff `git rev-list --reverse -n 2 HEAD -- $1` -- $1"
>
> FWIW, you can also do this as:
>  ldiff = log -p -1 --format=format: --
>
>> ldifft = "!git difftool `git rev-list --reverse -n 2 HEAD -- $1` -- $1"
>
> I don't know that you can do something equivalent with difftool. I
> suppose you could do the above with "GIT_EXTERNAL_DIFF=<some difftool
> wrapper> git ldiff", but that's not very helpful.

difftool cannot be driven by log right now.  It is something we
thought would be helpful in the past:

http://thread.gmane.org/gmane.comp.version-control.git/114269/focus=114367

On 2009-03-23 Junio C Hamano <gitster <at> pobox.com> wrote:
> Perhaps we would want a convenient way for "log -p" or "show -p" to drive
> difftool as a backend?

I think that's exactly it.  difftool wraps diff; a log equivalent
would be quite helpful.

One idea is for difftool to learn a "--log" option to make it wrap log
instead.  I don't know if a diff-like command having a "--log" option
is ideal from a consistency-of-user-interface POV so I'm open to
ideas.  It is convenient, though.  It does seem like difftool would be
a good place to expose this feature.

I'd be interested in the "teach log / show -p about GIT_EXTERNAL_DIFF"
route, if that sounds like a good idea.
-- 
            David

```

## Michael Horowitz, 2011-12-31 21:31

Subject: Re: git alias question
Message-ID: <CAFLRborAuoWKxOeHtPRujSYbQPk67RCxTiVBavtWDeh-Byfa2w@mail.gmail.com>
URL: https://gitlist.dev/e/CAFLRborAuoWKxOeHtPRujSYbQPk67RCxTiVBavtWDeh-Byfa2w%40mail.gmail.com
In-Reply-To: <CAJDDKr5a8TB82h4ULWtamLOVu_4Fv+cGw1YfEL987gM3yM4TMg@mail.gmail.com>

```
The log operation does seem to make the most sense as the mechanism to
search for the results.  Making it work with difftool would work...
Not sure if "--log" to difftool or some other options as suggested in
the other thread would be most consistent UI-wise as stated, but
either would work for me.

On a separate note, some environment variable like GIT_PREFIX with the
CWD would make the alias functionality more flexible.

Mike

On Thu, Dec 29, 2011 at 8:59 PM, David Aguilar <davvid@gmail.com> wrote:
>
> On Thu, Dec 29, 2011 at 9:08 AM, Dave Borowitz <dborowitz@google.com> wrote:
> > On Wed, Dec 28, 2011 at 17:27, Michael Horowitz
> > <michael.horowitz@ieee.org> wrote:
> >> ldiff = "!git diff `git rev-list --reverse -n 2 HEAD -- $1` -- $1"
> >
> > FWIW, you can also do this as:
> >  ldiff = log -p -1 --format=format: --
> >
> >> ldifft = "!git difftool `git rev-list --reverse -n 2 HEAD -- $1` -- $1"
> >
> > I don't know that you can do something equivalent with difftool. I
> > suppose you could do the above with "GIT_EXTERNAL_DIFF=<some difftool
> > wrapper> git ldiff", but that's not very helpful.
>
> difftool cannot be driven by log right now.  It is something we
> thought would be helpful in the past:
>
> http://thread.gmane.org/gmane.comp.version-control.git/114269/focus=114367
>
> On 2009-03-23 Junio C Hamano <gitster <at> pobox.com> wrote:
> > Perhaps we would want a convenient way for "log -p" or "show -p" to drive
> > difftool as a backend?
>
> I think that's exactly it.  difftool wraps diff; a log equivalent
> would be quite helpful.
>
> One idea is for difftool to learn a "--log" option to make it wrap log
> instead.  I don't know if a diff-like command having a "--log" option
> is ideal from a consistency-of-user-interface POV so I'm open to
> ideas.  It is convenient, though.  It does seem like difftool would be
> a good place to expose this feature.
>
> I'd be interested in the "teach log / show -p about GIT_EXTERNAL_DIFF"
> route, if that sounds like a good idea.
> --
>             David

```

## Jakub Narebski, 2011-12-31 23:30

Subject: Re: git alias question
Message-ID: <m3zke8e2vh.fsf@localhost.localdomain>
URL: https://gitlist.dev/e/m3zke8e2vh.fsf%40localhost.localdomain
In-Reply-To: <CAFLRborAuoWKxOeHtPRujSYbQPk67RCxTiVBavtWDeh-Byfa2w@mail.gmail.com>

```
Michael Horowitz <michael.horowitz@ieee.org> writes:

> The log operation does seem to make the most sense as the mechanism to
> search for the results.  Making it work with difftool would work...
> Not sure if "--log" to difftool or some other options as suggested in
> the other thread would be most consistent UI-wise as stated, but
> either would work for me.
> 
> On a separate note, some environment variable like GIT_PREFIX with the
> CWD would make the alias functionality more flexible.

1f5d271 (setup: Provide GIT_PREFIX to built-ins, 2011-05-25) is
present in v1.7.7; 7cf16a1 (handle_alias: provide GIT_PREFIX to
!alias, 2011-04-27) is in 1.7.6

-- 
Jakub Narebski

```

## Michael Horowitz, 2012-01-02 05:57

Subject: Re: git alias question
Message-ID: <CAFLRbopp1ROfMqp3PVdUQ37_fdku2FtV-=pxuYk-YA-+_wgjPg@mail.gmail.com>
URL: https://gitlist.dev/e/CAFLRbopp1ROfMqp3PVdUQ37_fdku2FtV-%3DpxuYk-YA-%2B_wgjPg%40mail.gmail.com
In-Reply-To: <m3zke8e2vh.fsf@localhost.localdomain>

```
Nice, works perfectly!  Didn't notice that was there, guess last time
I looked, I was using an older version.  I see it is in the git config
man page and all now.

Thanks,

Mike



On Sat, Dec 31, 2011 at 6:30 PM, Jakub Narebski <jnareb@gmail.com> wrote:
>
> Michael Horowitz <michael.horowitz@ieee.org> writes:
>
> > The log operation does seem to make the most sense as the mechanism to
> > search for the results.  Making it work with difftool would work...
> > Not sure if "--log" to difftool or some other options as suggested in
> > the other thread would be most consistent UI-wise as stated, but
> > either would work for me.
> >
> > On a separate note, some environment variable like GIT_PREFIX with the
> > CWD would make the alias functionality more flexible.
>
> 1f5d271 (setup: Provide GIT_PREFIX to built-ins, 2011-05-25) is
> present in v1.7.7; 7cf16a1 (handle_alias: provide GIT_PREFIX to
> !alias, 2011-04-27) is in 1.7.6
>
> --
> Jakub Narebski

```
