Neither occurrence of $1 is being replaced. They are surrounded by single quotes. The ; echo
at the end of the line is just a comment. So it is not really doing anything. If you want that to be part of the alias you need to surround the whole thing with double quotes.
The <stashname>
is being added to the end of the line (I assume that is what the echo
is for?) The command you propose seems to want to echo something like stash@{n}
given the name of the stash. The alias below will do that. (though it is not very useful)
[alias]
load = "!git stash list | grep \" $1$\" | awk '{ print $1 }' | sed '$ s/:$//' #"
The first occurrence of $1 is replaced by the argument because it is only surrounded by double quotes; which we need to escape. The $1 for awk will not be replaced be <stashname>
. Besides git already allows you to apply, pop stashed by name.
$ git stash list # produces no output
$ echo "something" > else.txt
$ git stash something
Saved working directory and index state On master: something
HEAD is now at 6d3fcf0 merged
$ git load something
stash@{0}
perhaps it's easier to see it this way
[alias]
test = "! echo $1 '$2' \"$3\" end; # "
results in
$ git test first second third
first $2 third end