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

Git alias syntax help

From
ΣΝΣταύρος Ντέντος <stdedos@gmail.com>
Date
Jan 14, 2020, 15:21 UTC
Message-ID
<CAHMHMxWpLAnj3w8DGLMFbfy-A-pBjDxNdMeiM-fyuu-gnZyg+Q@mail.gmail.com>
Hello there,

I am having an issue with git-aliases - specifically, the intricacies involved in their syntax.

In general, the syntax is confusing to me, especially when it is _wise_ to use quotes inside a `!sh` alias. e.g. which one would be the correct one new = "!f() { : git log ; git log \"${1}@{1}..${1}@{0}\" \"$@\" ; } ; f" new = !f() { : git log ; git log "${1}@{1}..${1}@{0}" "$@" ; } ; f

(from converting this:
https://git.wiki.kernel.org/index.php/Aliases#What.27s_new.3F)
        new = !sh -c 'git log $1@{1}..$1@{0} "$@"'

The alias confusing me is more specifically this: https://git.wiki.kernel.org/index.php/Aliases#simple_diff_ignoring_line_number_changes

diffsort = !sh -c 'git diff "$@" | grep "^[+-]" | sort --key=1.2 | uniq -u -s1'

The output of: $ colordiff -su <(git diffsort HEAD^..HEAD) <(git diffsort HEAD^^..HEAD^) Files /dev/fd/63 and /dev/fd/62 are identical is a little unexpected, since I know for a fact that one of the referced commits is not a code block moved.

(and indeed, if I do it myself:
$ colordiff -su <(git diff HEAD^..HEAD | grep "^[+-]" | sort --key=1.2
| uniq -u -s1) <(git diff HEAD^^..HEAD^ | grep "^[+-]" | sort
--key=1.2 | uniq -u -s1)
--- /dev/fd/63 2020-01-14 17:17:45.103771745 +0200
+++ /dev/fd/62 2020-01-14 17:17:45.103771745 +0200
@@ -1,2 +1,13 @@
[....]

it works.

The issue I have found is: $@ is not expanded

Tested with:

diffsort = !sh -c 'echo "+git diff $@" | grep "^[+-]" | sort --key=1.2
| uniq -u -s1'
$ git diffsort HEAD^..HEAD
+git diff

I would appreciate if someone would clear out the air for me.
I think I have done my homework enough, and it is not trivially
obvious what is the correct thing to do.

I'll gladly take pointers though

Ντέντος Σταύρος
Next: Jeff King
Message 1 of 5 in “Git alias syntax help”
  1. Σταύρος ΝτέντοςJan 14, 2020
  2. Jeff KingJan 14, 2020
  3. Σταύρος ΝτέντοςJan 14, 2020
  4. Jeff KingJan 15, 2020
  5. Philip OakleyMar 28, 2020

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.