Basically I want to compare a local file in the current branch against the remote file, but also I would like to know if there is a way to mix Git aliases with Linux commands.
The script I created looks like this:
git show origin/$(git rev-parse --abbrev-ref HEAD):$1 > /tmp/xxx <br/>
git diff /tmp/xxx $1
Is there a way to do that as a Git alias instead of having to create scripts?
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.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 isnecessary 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 desiredcommands 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.