git bad config when piping commands

不羁岁月 提交于 2019-12-13 00:05:43

问题


Both of these commands work from the command line

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

and

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

When added to gitconfig under [alias]

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

I get fatal: bad config line 16 in file /Users/<me>/.gitconfig which is the second line. My initial problem was getting the current branch into an alias thanks to this answer. So I am mainly curious why both work on the command line, but only 1 can work in config. I am guessing it's the ' ' needs to be escaped, but that's just a guess.


回答1:


Your usage of single quotes looks fine.

The problem is the wildcard argument you are passing to grepis causing a syntax error.

Try double-escaping the wildcard:

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


来源:https://stackoverflow.com/questions/43658283/git-bad-config-when-piping-commands

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!