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

Re: diff alias which used to work in version 2.27, failing from version 2.28 onwards

From
Jeff King <peff@peff.net>
Date
Aug 24, 2023, 14:32 UTC
Message-ID
<20230824143211.GA3108100@coredump.intra.peff.net>
In-Reply-To
<31866645d2ac4cb1be17e35fae742cb2@cscs.ch>
On Thu, Aug 24, 2023 at 10:19:18AM +0000, Reverdell  Auriane wrote:
> 14:38:45.275964 git.c:439               trace: built-in: git diff a2028e7b^..a2028e7b a2028e7b 
> [...]
> Is that expected behavior? if yes, how is the right/clean way to
> discard the command line argument of the alias?

Yes, that's expected. Your alias was always a little broken by adding the extra argument, but "git diff" got a little more careful about its input in 8bfcb3a690 (git diff: improve range handling, 2020-06-12), which as part of v2.28.

The usual way for manipulating arguments in a shell snippet is to make a function, like:

  [alias]
  dici = "!f() { git diff ${1:-HEAD}^..${1:-HEAD}; }; f"

Then Git ends up running "f a2028e7b", and the shell does the rest. It's obviously a bit more verbose to write, but you're free to do even more manipulation (e.g., using the first non-option argument as the rev and taking the rest as options).

All that said, there is a shorthand that may make your alias obsolete. From "git help revisions":

         <rev>^-<n>, e.g. HEAD^-, HEAD^-2
             Equivalent to <rev>^<n>..<rev>, with <n> = 1 if not given.
So just:
  git diff a2028e7b^-
does what you want.
-Peff
Previous: Reverdell AurianeNext: Mikael Magnusson
Message 2 of 3 in “diff alias which used to work in version 2.27, failing from version 2.28 onwards”
  1. Reverdell AurianeAug 24, 2023
  2. Jeff KingAug 24, 2023
  3. Mikael MagnussonSep 9, 2023

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.