添加一个包含分号的Git别名 [英] Add a Git alias containing a semicolon

查看:190
本文介绍了添加一个包含分号的Git别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试创建一个别名时

When I try to create an alias

[alias]
    my-alias = submodule foreach 'git foo ; git bar'

Git(版本1.7.1)发出错误消息

Git (version 1.7.1) spews the error

user@host:/path/repo.git$ git my-alias
error: unclosed quote
fatal: Bad alias.my-alias string

看起来 .gitconfig 使用奇怪的解析规则,所以; 被视为开始一个行注释,甚至在一个报价单内。

It appears that .gitconfig uses weird parsing rules, so that ; is treated as starting a line comment, even inside of a quote.

推荐答案

将整个alias命令用双引号括起来:

Wrap the entire alias command in double quotes:

my-alias = "submodule foreach 'git foo ; git bar'"

双引号导致 .gitconfig 解析器传递分号。单引号仍然需要将参数分隔到 submodule foreach ;没有它们,它被解析为

The double quotes cause the .gitconfig parser to pass the semicolon. The single quotes are still needed to delimit the argument to submodule foreach; without them, it gets parsed as

submodule foreach 'git foo'
git bar

所以 git bar 只会在最后执行一次。

so that git bar only gets executed once, at the end.

这篇关于添加一个包含分号的Git别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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