git:致命:无法将分支切换到非提交“12382”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30935689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git: fatal: Cannot switch branch to a non-commit '12382'
提问by zaphodb
Someone else on my team created a new git branch, committed and pushed to the usual remote that we work with. When I try to check out this branch, I get this:
我团队中的其他人创建了一个新的 git 分支,提交并推送到我们使用的常用远程。当我尝试查看这个分支时,我得到了这个:
% git checkout 12382
fatal: Cannot switch branch to a non-commit '12382'
I have not had trouble checking out other branches from this repository; tried checking another one out right after this (one that I did not have a local copy of), and it worked fine.
我从这个存储库中检出其他分支没有问题;尝试在此之后立即检查另一个(我没有本地副本的一个),并且运行良好。
I tried building a server with this branch on our Go pipeline, it worked fine - which means the server was successful in checking out that branch.
我尝试在 Go 管道上使用此分支构建服务器,它运行良好 - 这意味着服务器已成功检查该分支。
Tried this to check the status of things:
试过这个来检查事物的状态:
% git remote show origin
* remote origin
Fetch URL: [email protected]:mycompany/myrepository.git
Push URL: [email protected]:mycompany/myrepository.git
HEAD branch: stage
Remote branches:
10112 tracked
10198 tracked
10678 tracked
...
12382 tracked <<<---
...
Local branches configured for 'git pull':
...
Local refs configured for 'git push':
...
Could anyone suggest how to fix this? What went wrong?
谁能建议如何解决这个问题?什么地方出了错?
回答by knittl
Git is confused, because 12382
looks like a commit hash. Use the fully qualified name to checkout the branch:
Git 很困惑,因为它12382
看起来像一个提交哈希。使用完全限定名称签出分支:
git checkout refs/heads/12382 --
or, if it's a remote branch:
或者,如果它是远程分支:
git checkout refs/remotes/origin/12382 --
回答by zaphodb
@knittl: thanks that worked, had to do the following additional steps:
@knittl:感谢有效,必须执行以下附加步骤:
% git checkout refs/remotes/origin/12382
Note: checking out 'refs/remotes/origin/12382'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at 2d834e4...
% git branch | grep 12382
* (detached from origin/12382)
% git checkout -b 12382
Switched to a new branch '12382'
% git status
On branch 12382
nothing to commit, working directory clean
% git push --set-upstream origin 12382
Branch 12382 set up to track remote branch 12382 from origin.
Everything up-to-date
回答by Honey
The question is an edge case and it's already been answered.
这个问题是一个边缘情况,它已经得到了回答。
I'll answer the error on a more general level:
我将在更一般的层面上回答错误:
To be able to switch/checkout to something in your source tree it must be of type:
为了能够切换/检出源代码树中的某些内容,它必须是以下类型:
- commit :
git checkout: 90392aeda17d730d472493bc5a36237407c80979
or perhaps just do the first 7 digits ``git checkout: 90392ae` - tag
git checkout V2.0.3
- branch (remote branches too)
git checkout newLogin
- HEAD
git checkout HEAD^1
- Hash, short Hash.
- 提交:
git checkout: 90392aeda17d730d472493bc5a36237407c80979
或者只是做前 7 位数字``git checkout: 90392ae` - 标签
git checkout V2.0.3
- 分支(也有远程分支)
git checkout newLogin
- 头
git checkout HEAD^1
- 哈希,简称哈希。
So if you are switching to something that is none of them, like you mistyped your branch name, git would give you this error.
因此,如果您要切换到它们都不是的东西,例如您输入错误的分支名称,git 会给您这个错误。
Cannot switch branch to a non-commitmeans the think you are trying to checkout to something that isn't tree-ish
无法将分支切换到非提交意味着认为您正在尝试结帐到不是树状的东西