简体   繁体   English

如何签出具有特殊字符“-”的分支名称?

[英]How can I checkout a branch name having special character '-'?

I created a git branch name -new-br :我创建了一个 git 分支名称-new-br

git checkout -b -new-br.

I switched back to parent branch.我切换回父分支。

Now I am unable to checkout -new-br .现在我无法结帐-new-br

git checkout -new-br.
getting error:
error: unknown switch `n'
usage: git checkout [options] <branch>
   or: git checkout [options] [<branch>] -- <file>...

How can I check this branch out?我如何检查这个分支?

Many Unix commands accept -- to mean "no more switches" and further arguments aren't then parsed as switches.许多 Unix 命令接受--表示“不再有开关”,并且进一步的参数不会被解析为开关。 See " What does “--” (double-dash) mean? " on this adjacent site .请参阅此相邻站点上的““--”(双破折号)是什么意思? ”。

So...所以...

git checkout -- -new-br

...would probably suffice. ……应该就够了。

However... which version of Git are you using to create such a branch?但是……您使用哪个版本的 Git 来创建这样的分支? Git version 1.8.4 tells me: Git 1.8.4 版告诉我:

git checkout -b -new-br
fatal: '-new-br' is not a valid branch name.

Trying it another way...换个方式试试...

git branch -- -new-br
fatal: '-new-br' is not a valid branch name

I suggest that you check the names of all your branches with:我建议您检查所有分支机构的名称:

git branch --list --all

Reference:参考:

If you have an existing branch like that, you can rename it by changing the reference file for the branch:如果您有这样的现有分支,您可以通过更改分支的参考文件来重命名它:

mv .git/refs/heads/-new-br .git/refs/heads/new-br

After that, you can check it out using git checkout new-br .之后,您可以使用git checkout new-br来检查它。

This works!这有效! Add your branch name inside quotes在引号内添加您的分支名称

git checkout '<new-branch-name>'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM