问题
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 grep
is 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