kostja
kostja

Reputation: 61538

Using curly braces referencing git revisions/references fails

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?

Upvotes: 6

Views: 1795

Answers (1)

mklement0
mklement0

Reputation: 437688

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.

Upvotes: 6

Related Questions