This question Add a Git alias containing a semicolon shows that semicolons in a git alias command need special handling.
But even with the double quotes that answer suggests, I am finding some things don’t work.
E.g.:
related = "!perl -e '$branch = qx[git rev-parse --abbrev-ref HEAD]; ($issue) = $branch =~ m[^(d+)]; print $issue;'"
produces:
fatal: bad config line 23
What does git dislike with the command?
1
d
is not a valid escape sequence. You want your alias to contain a backslash followed by a d, therefore you must escape the backslash itself. The following works:
related = "!perl -e '$branch = qx[git rev-parse --abbrev-ref HEAD]; ($issue) = $branch =~ m[^(\d+)]; print $issue;'"
Or let Git handle the escaping of your alias values by not editing the .gitconfig
file manually, but going through the git config
command:
git config --global alias.related '!perl -e '''$branch = qx[git rev-parse --abbrev-ref HEAD]; ($issue) = $branch =~ m[^(d+)]; print $issue;''
(this will produce the same config line as shown above)
0