git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git alias question

From
MHMichael Horowitz <michael.horowitz@ieee.org>
Date
Dec 29, 2011, 01:27 UTC
Message-ID
<CAFLRbopjqW7OEWN4kxy+6Gb828h4zBC_h=4WiP-q1__LeezxUw@mail.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
Next: Miles Bader
Message 1 of 8 in “git alias question”
  1. Michael HorowitzDec 29, 2011
  2. Miles BaderDec 29, 2011
  3. Junio C HamanoDec 29, 2011
  4. Dave BorowitzDec 29, 2011
  5. David AguilarDec 30, 2011
  6. Michael HorowitzDec 31, 2011
  7. Jakub NarebskiDec 31, 2011
  8. Michael HorowitzJan 2, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.