-->

管道命令时坏的git配置(git bad config when piping commands)

2019-09-28 05:16发布

这两个命令的命令行工作

git symbolic-ref HEAD | sed -e "s#^refs/heads/##"

git branch | grep \* | cut -d ' ' -f2 

当加入[别名]下gitconfig

thisbranch = !git symbolic-ref HEAD | sed -e "s#^refs/heads/##"
thisbranch2 = !git branch | grep \* | cut -d ' ' -f2

我得到fatal: bad config line 16 in file /Users/<me>/.gitconfig这是第二行。 我最初的问题是获取当前分支成一个别名感谢这个答案 。 所以我主要是好奇,为什么在命令行上都工作,但只有1个可以配置工作。 我猜测它的' '需要转义,但是这只是一个猜测。

Answer 1:

你的单引号的使用看起来不错。

问题是要传递到通配符参数grep导致语法错误。

尝试双转义通配符:

thisbranch2 = !git branch | grep \\* | cut -d ' ' -f2


文章来源: git bad config when piping commands
标签: git git-alias