通用解决方案
让git 别名正确传递解析器可能是一组令人难以置信的\\\\" 噪音,所以我创建了两个别名:
# Quote / unquote a sh command, converting it to / from a git alias string
quote-string = "!read -r l; printf \\\"!; printf %s \"$l\" | sed 's/\\([\\\"]\\)/\\\\\\1/g'; printf \" #\\\"\\n\" #"
quote-string-undo = "!read -r l; printf %s \"$l\" | sed 's/\\\\\\([\\\"]\\)/\\1/g'; printf \"\\n\" #"
这允许您将任何可以输入的内容转换为sh+,例如:
$ echo '\"'
\"
放入适合别名的带引号的字符串:
$ git quote-string
echo '\"'
"!echo '\\\"' #"
为了引用一个多行字符串,我写了一个更长的script,我建议你这样运行:
git quote-string |sponge
回答 OP 的具体问题
在 OP 的命令上使用 git quote-string,我得到:
"!git filter-branch -f --msg-filter \"sed -e \\\"s/\\[ci skip\\]$//g\\\"\" master..HEAD #"
因此,要使用 OP 的首选别名,请在 [alias] 中的 ~/.gitconfig 下添加:
unwip = "!git filter-branch -f --msg-filter \"sed -e \\\"s/\\[ci skip\\]$//g\\\"\" master..HEAD #"
调试
有时很高兴看到引擎盖下发生了什么。试试这个别名:
debug = "!set -x; GIT_TRACE=2 GIT_CURL_VERBOSE=2 GIT_TRACE_PERFORMANCE=2 GIT_TRACE_PACK_ACCESS=2 GIT_TRACE_PACKET=2 GIT_TRACE_PACKFILE=2 GIT_TRACE_SETUP=2 GIT_TRACE_SHALLOW=2 git"
只需在 git 之间插入 debug 和通常会出现的任何内容,例如对于 OP 的问题:
git debug unwip
+ git 使用/bin/sh 来执行以!* 开头的别名。要解决此问题,请创建如下命令行:bash -c 'echo \\\"',然后将其传递给 git quote-string。
* 参见“调试”标题以获得证明