通用解决方案
让一个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的具体问题
使用git quote-stringOP 的命令,我得到:
"!git filter-branch -f --msg-filter \"sed -e \\\"s/\\[ci skip\\]$//g\\\"\" master..HEAD #"
因此,要使用 OP 的首选别名,请在[alias]in下~/.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"
只需插入debug通常git会遵循的内容,例如对于 OP 的问题:
git debug unwip
+ git用于执行以*/bin/sh开头的别名。要解决此问题,请创建一个命令行,如:,然后将其传递给.!bash -c 'echo \\\"'git quote-string
*请参阅“调试”标题以获得证明