管道命令时git错误配置 [英] git bad config when piping commands

查看:134
本文介绍了管道命令时git错误配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两个命令都可以从命令行运行。

  git symbolic-ref HEAD | sed -es#^ refs / heads / ##

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

在[alias]下添加到gitconfig中时

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

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

解决方案您的单引号使用看起来很好。



问题是您传递给 grep

尝试双重转义通配符:

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


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.

解决方案

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

这篇关于管道命令时git错误配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆