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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With