1

这两个命令都从命令行工作

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

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

在 [alias] 下添加到 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 可以在配置中工作。我猜这是' '需要逃避的,但这只是一个猜测。

4

1 回答 1

1

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

问题是您传递给的通配符参数grep导致语法错误。

尝试双重转义通配符:

thisbranch2 = !git branch | grep \\* | cut -d ' ' -f2
于 2017-04-27T12:51:24.337 回答