Git checkout:更新路径与切换分支不兼容
我的问题与切换分支时发生致命 Git 错误有关。
我尝试使用命令获取远程分支
git checkout -b local-name origin/remote-name
,但收到以下错误消息:
致命:git checkout:更新路径与切换分支不兼容。
您是否打算签出无法解析为提交的“origin/remote-name”?
如果我手动创建一个分支,然后拉出远程分支,它就会起作用,就像创建一个新的克隆并签出分支一样。
为什么它在我使用的存储库上不起作用?
My problem is related to Fatal Git error when switching branch.
I try to fetch a remote branch with the command
git checkout -b local-name origin/remote-name
but I get this error message:
fatal: git checkout: updating paths is incompatible with switching branches.
Did you intend to checkout 'origin/remote-name' which can not be resolved as commit?
If I manually create a branch and then pull the remote branch, it works, just as making a new clone and checking the branch out.
Why does it not work on the repository I work with?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
我相信当您尝试签出本地 git 存储库尚不知道的远程分支时,就会发生这种情况。 尝试:
如果您要签出的远程分支位于“新远程分支”而不是“跟踪的远程分支”下,那么您需要先获取它们:
现在它应该可以工作:
I believe this occurs when you are trying to checkout a remote branch that your local git repo is not aware of yet. Try:
If the remote branch you want to checkout is under "New remote branches" and not "Tracked remote branches" then you need to fetch them first:
Now it should work:
替代语法,
Alternate syntax,
在尝试了该线程中我能读到的大部分内容但没有成功之后,我偶然发现了这一点:
远程分支未显示在“git分支 - r"
原来我的 .git/config 文件不正确。 进行简单的修复后,所有分支都出现了。
从
到
成功了吗
After having tried most of what I could read in this thread without success, I stumbled across this one:
Remote branch not showing up in "git branch -r"
It turned out that my .git/config file was incorrect. After doing a simple fix all branches showed up.
Going from
to
Did the trick
不确定这是否有帮助或与您的问题完全相关,但如果您尝试从远程存储库中仅获取并签出单个分支,那么以下 git 命令就可以解决问题:
Not sure if this is helpful or exactly relevant to your question, but if you are trying to fetch and checkout only a single branch from the remote repository, then the following git commands will do the trick:
以上都不适合我。 我的情况略有不同,我的远程分支不在原点。 但在不同的存储库中。
提示:如果您在以下输出中没有看到远程分支 gitbranch -v -a ,则无法检查它。
已确认在 1.7.5.4 上运行
none of the above worked for me. My situation is slightly different, my remote branch is not at origin. but in a different repository.
tip: if you don't see the remote branch in the following output
git branch -v -a
there is no way to check it out.Confirmed working on 1.7.5.4
对我来说,有效的是:
将远程所有分支的所有引用拉到您的机器上。 然后我就可以做
并且效果非常好。 与得票最高的答案类似,但更简单一些。
For me what worked was:
Which pulls all the refs down to your machine for all the branches on remote. Then I could do
and that worked perfectly. Similar to the top voted answer, but a little more simple.
我怀疑没有名为remote-name的远程分支,但您无意中创建了名为origin/remote-name的本地分支。
您是否有可能在某个时候输入:
因此创建一个名为 origin/remote-name 的本地分支? 键入此命令:
您将看到:
这意味着它确实是一个命名错误的本地分支,或者
这意味着它确实是一个远程分支。
I suspect there is no remote branch named remote-name, but that you've inadvertently created a local branch named origin/remote-name.
Is it possible you at some point typed:
Thus creating a local branch named origin/remote-name? Type this command:
You'll either see:
which means it's really a mis-named local branch, or
which means it really is a remote branch.
这不是很直观,但这对我来说效果很好......
然后运行 gitbranch --track 命令......
It's not very intuitive but this works well for me ...
THEN run the git branch --track command ...
对我来说,我有一个拼写错误,我的远程分支不存在
使用 gitbranch -a 列出远程分支
For me I had a typo and my remote branch didn't exist
Use
git branch -a
to list remote branches您的问题是否可以与其他问题“结帐问题”相关联?
即:与以下内容相关的问题:
git checkout -b [] []
,其中[]
指的是启动新分支的提交名称,而'origin/remote-name'
不是这样。(而
git 分支
< /a> 确实支持 start_point 作为远程分支的名称)注意: checkout.sh 脚本 说的是:
这就像语法 git checkout -b [] [remote_branch_name] 既重命名分支又重置新分支的新起点,这被认为是不兼容的。
Could your issue be linked to this other SO question "checkout problem"?
i.e.: a problem related to:
git checkout -b [<new_branch>] [<start_point>]
, with[<start_point>]
referring to the name of a commit at which to start the new branch, and'origin/remote-name'
is not that.(whereas
git branch
does support a start_point being the name of a remote branch)Note: what the checkout.sh script says is:
It is like the syntax git checkout -b [] [remote_branch_name] was both renaming the branch and resetting the new starting point of the new branch, which is deemed incompatible.
获取无数次后,添加的遥控器仍然没有出现,尽管斑点在池中。 事实证明,无论出于何种原因,都不应该将 --tags 选项提供给
git remote add
。 您可以手动将其从 .git/config 中删除,以使 git fetch 创建引用。After fetching a zillion times still added remotes didn't show up, although the blobs were in the pool. Turns out the --tags option shouldn't be given to
git remote add
for whatever reason. You can manually remove it from the .git/config to make git fetch create the refs.