An alias will be passed to the shell for execution if the value begins with the
!
character. So it is possible to define an alias to do what you want.
[alias]
diff-remote = "!f() { git show origin/$(git rev-parse --abbrev-ref HEAD):$GIT_PREFIX$1 > /tmp/xxx; git diff /tmp/xxx $GIT_PREFIX$1; }; f"
Aliases are always run from the top directory of the repository, with the path
from there to the original directory stored in $GIT_PREFIX
. So it is
necessary to prepend that to file names in order for an alias to work from
other directories within the repository.
But, to do that it is necessary to put the actual code into a function.
Otherwise there is no way for that variable to be inserted immediately before
the first argument.
So this alias definition defines a shell function (named f
) with the desired
commands and then immediately runs that. There's no need to cleanup the
temporary function because that shell will be exiting right after the function
does.