使用大括号引用git修订/引用失败 [英] Using curly braces referencing git revisions/references fails
问题描述
git checkout stash @ {0} - some / file
这会导致致命:invalid reference:stash @ 0
看起来大括号已被消除,但我不确定这个罪魁祸首。
存储版本在那里。 git存储清单
退货
存储@ {0}:WIP on X
stash @ {1}:WIP on Y
我使用git 1.9.1 zsh。
有没有一种方法可以防止消除大括号?
<引用包含 {...}
序列的字符串通常更好(例如, git checkout'stash @ {0}')。 。
),因为它们需要大括号扩展。
(或者,就此而言,单引号任何要保留的字符串字面值 )。但是,在 默认 zsh
环境中, > 不成为问题,因为 {0}
不是有效的大括号表达式因此只需按原样打印(同样适用于 bash
, dash
和 ksh
);验证:
echo stash @ {0}#在bash,dash,ksh,zsh中按原样打印(默认选项为效果)
赞美 chepner 因怀疑 BRACE_CLL
zsh
选项可能被设置为,这确实产生了这样的症状:
$ setopt BRACE_CCL
$ echo stash @ {0}
stash @ 0#!!大括号删除
正如chepner所述, BRACE_CCL
导致 {0}
被视为包含一个字符的字符类,而不是逐字处理。换句话说: BRACE_CCL
展开 {...}
中的每个单独字符 , echo一个{01}
- > a0 a1
),并且仅指定一个字符,净效果是去除封闭的大括号。
由于OP自己确认, unsetopt BRACE_CCL
解决了这个问题。
I am trying to checkout a single file from stash:
git checkout stash@{0} -- some/file
This fails with fatal: invalid reference: stash@0
Looks like the curly braces are eliminated, but I am not sure about the culprit.
The stash revision is there. git stash list
returns
stash@{0}: WIP on X
stash@{1}: WIP on Y
I am using git 1.9.1 on zsh.
Is there a way to prevent this brace elimination?
It is generally better to quote strings that contain {...}
sequences (e.g., git checkout 'stash@{0}' ...
), because they are subject to brace expansion.
(Or, for that matter, single-quote any string literal you want to preserve as is.)
However, in a default zsh
environment this would not be a problem, because {0}
is not a valid brace expression and is therefore simply printed as is (equally applies to bash
, dash
, and ksh
); verify with:
echo stash@{0} # prints as is in bash, dash, ksh, zsh (with default options in effect)
Kudos to chepner for suspecting that the BRACE_CLL
zsh
option may be set, which indeed does produce the symptom:
$ setopt BRACE_CCL
$ echo stash@{0}
stash@0 # !! braces removed
As chepner states, BRACE_CCL
"causes {0}
to be treated as a character class containing one character, rather than being treated literally"; in other words: BRACE_CCL
expands each individual character inside {...}
(e.g., echo a{01}
-> a0 a1
) and with just one character specified, the net effect is removal of the enclosing braces.
As the OP himself has since confirmed, unsetopt BRACE_CCL
solved the problem.
这篇关于使用大括号引用git修订/引用失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!