Git checkout:更新路径与切换分支不兼容

发布于 2024-07-23 06:36:51 字数 406 浏览 11 评论 0原文

我的问题与切换分支时发生致命 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

清风疏影 2024-07-30 06:36:51

我相信当您尝试签出本地 git 存储库尚不知道的远程分支时,就会发生这种情况。 尝试:

git remote show origin

如果您要签出的远程分支位于“新远程分支”而不是“跟踪的远程分支”下,那么您需要先获取它们:

git remote update
git fetch

现在它应该可以工作:

git checkout -b local-name origin/remote-name

I believe this occurs when you are trying to checkout a remote branch that your local git repo is not aware of yet. Try:

git remote show origin

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:

git remote update
git fetch

Now it should work:

git checkout -b local-name origin/remote-name
傲影 2024-07-30 06:36:51

替代语法,

git fetch origin remote_branch_name:local_branch_name

Alternate syntax,

git fetch origin remote_branch_name:local_branch_name
在巴黎塔顶看东京樱花 2024-07-30 06:36:51

在尝试了该线程中我能读到的大部分内容但没有成功之后,我偶然发现了这一点:
远程分支未显示在“git分支 - r"

原来我的 .git/config 文件不正确。 进行简单的修复后,所有分支都出现了。

[remote "origin"]
    url = http://stash.server.com/scm/EX/project.git
    fetch = +refs/heads/master:refs/remotes/origin/master

[remote "origin"]
    url = http://stash.server.com/scm/EX/project.git
    fetch = +refs/heads/*:refs/remotes/origin/*

成功了吗

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

[remote "origin"]
    url = http://stash.server.com/scm/EX/project.git
    fetch = +refs/heads/master:refs/remotes/origin/master

to

[remote "origin"]
    url = http://stash.server.com/scm/EX/project.git
    fetch = +refs/heads/*:refs/remotes/origin/*

Did the trick

我纯我任性 2024-07-30 06:36:51

不确定这是否有帮助或与您的问题完全相关,但如果您尝试从远程存储库中仅获取并签出单个分支,那么以下 git 命令就可以解决问题:

url= << URL TO REPOSITORY >>
branch= << BRANCH NAME >>

git init
git remote add origin $url
git fetch origin $branch:origin/$branch
git checkout -b $branch --track origin/$branch

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:

url= << URL TO REPOSITORY >>
branch= << BRANCH NAME >>

git init
git remote add origin $url
git fetch origin $branch:origin/$branch
git checkout -b $branch --track origin/$branch
耀眼的星火 2024-07-30 06:36:51

以上都不适合我。 我的情况略有不同,我的远程分支不在原点。 但在不同的存储库中。

git remote add remoterepo GIT_URL.git
git fetch remoterepo
git checkout -b branchname remoterepo/branchname

提示:如果您在以下输出中没有看到远程分支 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.

git remote add remoterepo GIT_URL.git
git fetch remoterepo
git checkout -b branchname remoterepo/branchname

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

灯角 2024-07-30 06:36:51

对我来说,有效的是:

git fetch

将远程所有分支的所有引用拉到您的机器上。 然后我就可以做

git checkout <branchname>

并且效果非常好。 与得票最高的答案类似,但更简单一些。

For me what worked was:

git fetch

Which pulls all the refs down to your machine for all the branches on remote. Then I could do

git checkout <branchname>

and that worked perfectly. Similar to the top voted answer, but a little more simple.

软糖 2024-07-30 06:36:51

我怀疑没有名为remote-name的远程分支,但您无意中创建了名为origin/remote-name的本地分支。

您是否有可能在某个时候输入:

git branch origin/remote-name

因此创建一个名为 origin/remote-name 的本地分支? 键入此命令:

git checkout origin/remote-name

您将看到:

Switched to branch "origin/remote-name"

这意味着它确实是一个命名错误的本地分支,或者

Note: moving to "origin/rework-isscoring" which isn't a local branch
If you want to create a new branch from this checkout, you may do so
(now or later) by using -b with the checkout command again. Example:
  git checkout -b 

这意味着它确实是一个远程分支。

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:

git branch origin/remote-name

Thus creating a local branch named origin/remote-name? Type this command:

git checkout origin/remote-name

You'll either see:

Switched to branch "origin/remote-name"

which means it's really a mis-named local branch, or

Note: moving to "origin/rework-isscoring" which isn't a local branch
If you want to create a new branch from this checkout, you may do so
(now or later) by using -b with the checkout command again. Example:
  git checkout -b 

which means it really is a remote branch.

小霸王臭丫头 2024-07-30 06:36:51

这不是很直观,但这对我来说效果很好......

  mkdir remote.git & cd remote.git & git init
  git remote add origin $REPO
  git fetch origin $BRANCH:refs/remotes/origin/$BRANCH        

然后运行 ​​gitbranch --track 命令......

  git branch --track $BRANCH origin/$BRANCH

It's not very intuitive but this works well for me ...

  mkdir remote.git & cd remote.git & git init
  git remote add origin $REPO
  git fetch origin $BRANCH:refs/remotes/origin/$BRANCH        

THEN run the git branch --track command ...

  git branch --track $BRANCH origin/$BRANCH
五里雾 2024-07-30 06:36:51

对我来说,我有一个拼写错误,我的远程分支不存在

使用 gitbranch -a 列出远程分支

For me I had a typo and my remote branch didn't exist

Use git branch -a to list remote branches

枕头说它不想醒 2024-07-30 06:36:51

您的问题是否可以与其他问题“结帐问题”相关联?

即:与以下内容相关的问题:

注意: checkout.sh 脚本 说的是:

  if test '' != "$newbranch$force$merge"
  then
    die "git checkout: updating paths is incompatible with switching branches/forcing$hint"
  fi

这就像语法 git checkout -b [] [remote_branch_name] 既重命名分支又重置新分支的新起点,这被认为是不兼容的。

Could your issue be linked to this other SO question "checkout problem"?

i.e.: a problem related to:

  • an old version of Git
  • a curious checkout syntax, which should be: 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:

  if test '' != "$newbranch$force$merge"
  then
    die "git checkout: updating paths is incompatible with switching branches/forcing$hint"
  fi

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.

遥远的绿洲 2024-07-30 06:36:51

获取无数次后,添加的遥控器仍然没有出现,尽管斑点在池中。 事实证明,无论出于何种原因,都不应该将 --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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文