{"thread":{"id":"60150","subject":"diff alias which used to work in version 2.27, failing from version 2.28 onwards","startedAt":"2023-08-24T10:20:05Z","lastAt":"2023-09-09T18:45:11Z","messageCount":3,"participants":["Reverdell Auriane","Jeff King","Mikael Magnusson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"480989","messageId":"31866645d2ac4cb1be17e35fae742cb2@cscs.ch","threadId":"60150","inReplyTo":null,"subject":"diff alias which used to work in version 2.27, failing from version 2.28 onwards","fromName":"Reverdell Auriane","fromEmail":"auriane.reverdell@cscs.ch","sentAt":"2023-08-24T10:19:18Z","receivedAt":"2023-08-24T10:20:05Z","isPatch":false,"sender":{"key":"auriane.reverdell@cscs.ch","avatar":null},"body":"Hi,\n\nTo output the diff of a specific commit, I created the alias dici (see below), git dici 12345 or git dici to output the diff of the HEAD:\n\n[alias]\n    dici = !git diff ${1:-HEAD}^..${1:-HEAD}\n\na trace for this alias gives (same trace for both git 2.27 and 2.28!):\n\n14:38:45.275964 git.c:439               trace: built-in: git diff a2028e7b^..a2028e7b a2028e7b \n\nThe commit number is put again at the end of the command (the wanted alias is supposed to output only `git diff a2028e7b^..a2028e7b`), this was accepted by version 2.27 but not by the version 2.28. For now, my temporary fix is adding a bash comment at the end of the alias:\n\n[alias]\n    dici = \"!git diff ${1:-HEAD}^..${1:-HEAD} #\"\n\nNote: the first alias still doesn't work with the latest git versions (tested with 2.40.0, 2.39.2, 2.37.5).\n\nIs that expected behavior? if yes, how is the right/clean way to discard the command line argument of the alias?\n\nThanks in advance!\n\nAuriane\n"},{"id":"480993","messageId":"20230824143211.GA3108100@coredump.intra.peff.net","threadId":"60150","inReplyTo":"31866645d2ac4cb1be17e35fae742cb2@cscs.ch","subject":"Re: diff alias which used to work in version 2.27, failing from version 2.28 onwards","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2023-08-24T14:32:11Z","receivedAt":"2023-08-24T14:33:13Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Aug 24, 2023 at 10:19:18AM +0000, Reverdell  Auriane wrote:\n\n> 14:38:45.275964 git.c:439               trace: built-in: git diff a2028e7b^..a2028e7b a2028e7b \n> [...]\n> Is that expected behavior? if yes, how is the right/clean way to\n> discard the command line argument of the alias?\n\nYes, that's expected. Your alias was always a little broken by adding\nthe extra argument, but \"git diff\" got a little more careful about its\ninput in 8bfcb3a690 (git diff: improve range handling, 2020-06-12),\nwhich as part of v2.28.\n\nThe usual way for manipulating arguments in a shell snippet is to make a\nfunction, like:\n\n  [alias]\n  dici = \"!f() { git diff ${1:-HEAD}^..${1:-HEAD}; }; f\"\n\nThen Git ends up running \"f a2028e7b\", and the shell does the rest. It's\nobviously a bit more verbose to write, but you're free to do even more\nmanipulation (e.g., using the first non-option argument as the rev and\ntaking the rest as options).\n\nAll that said, there is a shorthand that may make your alias obsolete.\nFrom \"git help revisions\":\n\n         <rev>^-<n>, e.g. HEAD^-, HEAD^-2\n             Equivalent to <rev>^<n>..<rev>, with <n> = 1 if not given.\n\nSo just:\n\n  git diff a2028e7b^-\n\ndoes what you want.\n\n-Peff\n"},{"id":"481628","messageId":"CAHYJk3SfG01wqFDC0O_iUueBn6JXi6kydyfGGoZfd5kgVVSfbw@mail.gmail.com","threadId":"60150","inReplyTo":"31866645d2ac4cb1be17e35fae742cb2@cscs.ch","subject":"Re: diff alias which used to work in version 2.27, failing from version 2.28 onwards","fromName":"Mikael Magnusson","fromEmail":"mikachu@gmail.com","sentAt":"2023-09-09T18:45:05Z","receivedAt":"2023-09-09T18:45:11Z","isPatch":false,"sender":{"key":"mikachu@gmail.com","avatar":null},"body":"On 8/24/23, Reverdell  Auriane <auriane.reverdell@cscs.ch> wrote:\n> Hi,\n>\n> To output the diff of a specific commit, I created the alias dici (see\n> below), git dici 12345 or git dici to output the diff of the HEAD:\n>\n> [alias]\n>     dici = !git diff ${1:-HEAD}^..${1:-HEAD}\n>\n> a trace for this alias gives (same trace for both git 2.27 and 2.28!):\n>\n> 14:38:45.275964 git.c:439               trace: built-in: git diff\n> a2028e7b^..a2028e7b a2028e7b\n>\n> The commit number is put again at the end of the command (the wanted alias\n> is supposed to output only `git diff a2028e7b^..a2028e7b`), this was\n> accepted by version 2.27 but not by the version 2.28. For now, my temporary\n> fix is adding a bash comment at the end of the alias:\n>\n> [alias]\n>     dici = \"!git diff ${1:-HEAD}^..${1:-HEAD} #\"\n>\n> Note: the first alias still doesn't work with the latest git versions\n> (tested with 2.40.0, 2.39.2, 2.37.5).\n>\n> Is that expected behavior? if yes, how is the right/clean way to discard the\n> command line argument of the alias?\n\nIf you want to interpolate arguments in the command string, the safest\nway is something like\ndici = !sh -c 'git diff ${1:-HEAD}~..${1:-HEAD}' sh\n\n(but why not just use git show?)\n\nyou can also use the ^! syntax instead:\ndici = !sh -c 'git diff ${1:-HEAD}^!' sh\n\n-- \nMikael Magnusson\n"}]}