为什么 git Branch -t 会失败并显示“未跟踪:信息不明确”?
当我尝试创建一个跟踪远程分支的新分支时,我得到:
$ git branch -t test origin/foo
error: Not tracking: ambiguous information for ref refs/remotes/origin/foo
源代码 似乎以某种方式搜索要跟踪的分支并将我抛出,因为它发现 less 超过一个,但我并没有完全明白它在寻找什么,因为我已经告诉它要跟踪什么在命令行上。
谁能告诉我发生了什么事以及如何解决它?
When I try to create a new branch tracking a remote branch, I get this:
$ git branch -t test origin/foo
error: Not tracking: ambiguous information for ref refs/remotes/origin/foo
The source seems to somehow search for branches to track and throws me out because it finds less more than one, but I don't exactly get what it's looking for since I already told it what to track on the command line.
Can anybody tell me what's going on and how to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
当我有两个具有相同(默认)获取模式(
fetch = +refs/heads/*:refs/remotes/origin/*
)和相同分支的远程存储库时,我也看到了这一点。最初的错误是创建两个具有相同
fetch
配置的遥控器。新的遥控器具有不同的名称,因此其文件夹的名称也应该更改。以下是正确的多远程配置的示例:用您选择的任何名称代替
alt
。说明:
refs/heads/*:refs/remotes/origin/*
的含义是:获取refs/heads
中的所有远程引用在远程端,并将refs/heads/origin
放在我们这边。refs/heads
是存储分支的路径,因此如果远程有分支foo
,它将被提取到origin/foo
在您本地的存储库中。开头的 + 表示目标分支应始终被覆盖(无需进行一些额外的检查)。或者:
您还可以手动将信息添加到项目的
.git/config
中,例如:I saw this also when I had two remote repo's with the same (default) fetch pattern (
fetch = +refs/heads/*:refs/remotes/origin/*
) and the same branches.The original mistake was in creating two remotes with the same
fetch
configuration. The new remote has a different name, and therefore the name of its folder should have been changed as well. Here is an example of a proper multiple-remote configuration:In place of
alt
put any name of your choosing.Explanation:
The meaning of
refs/heads/*:refs/remotes/origin/*
is: take all the remote reference inrefs/heads
on the remote side, and put the torefs/heads/origin
on our side.refs/heads
is the path where branches are stored, so if you have branchfoo
on the remote, it will be fetched toorigin/foo
in your local repo. The+
on the beginning means that the destination branches should be always overwritten (w/o that there are some additional checks).Alternatively:
You can also manually add the info to the project's
.git/config
, e.g.:否:因为它找到多于一个匹配的远程分支,这意味着函数
remote_find_tracking()
对于给定的本地分支返回多个跟踪分支参考号some_remote_branch
是否尚未被您的本地分支机构之一跟踪?(
git config -l
可以让您检查当前设置的内容)。(
git Branch -r
还可以帮助列出当前的远程跟踪分支。)另请参阅“复制从一个存储库到另一个存储库的分支”,了解 Git 2.36(2022 年第 2 季度)的更多详细信息。
错误的,如此帖子所示:
现在:
问题是,对于 git-merge:
考虑
remote_find_tracking()
采用单个遥控器和填充了 src 的 refspec,并在之后返回给定的 refspec如果为远程配置了适当的跟踪(即 git),则填充其 dst。可能它认为它已经有一个与
some_remote_branch
匹配的本地后续分支。您在当地有同名的分支机构吗?或者,相反:您当前的分支有一个具有相似名称的远程分支,这使其成为任何 git-merge 的自然候选者:尝试使其跟踪另一个分支> 远程分支将使 git-merge 无法选择要更新/合并远程更改的本地分支。
Nope: because it finds more than one matching remote branch, which means the function
remote_find_tracking()
returns more than one tracking branch for a given local branch ref.Is
some_remote_branch
not already tracked by one of your local branches?(a
git config -l
would allow you to check what you have currently have set up).(a
git branch -r
can also help to list your current remote-tracking branches. )See also "copy a branch from one to another repo" for more details with Git 2.36 (Q2 2022).
Wrong, as illustrated by this thread:
Now:
The problem is, for git-merge:
Consider that
remote_find_tracking()
takes a single remote and a refspec with src filled, and returns the given refspec after filling its dst, if an appropriate tracking was configured for the remote, meaning git.May be it considers it already has a local following branch matching
some_remote_branch
. Do you have any local branch with that exact same name?Or, the other way around: your current branch has a remote branch with a similar name, which makes it a natural candidate for any
git-merge
: trying to make it track another remote branch would make thegit-merge
unable to choose which local branch to update/merge with changes of a remote.知道了!问题是我之前已经使用
--mirror
设置了远程,以便拥有我的存储库的备份/公共副本。如果你运行
它,它不仅将远程标记为镜像(这就是我想要的推送),而且还将镜像的
remote..fetch
选项配置为+refs /*:refs/*
,这意味着您的所有分支突然“跟踪”您的镜像存储库,并且任何创建跟踪分支的尝试都将失败。(作为额外的好处,运行 git fetch将会用备份存储库中的旧引用覆盖所有引用。)
似乎解决此问题的解决方案是设置
remote ..fetch
到:
(我希望这意味着“从不获取任何内容”)。这显然解决了跟踪问题并消除了致命的获取。Got it! The problem was that I have previously set up a remote with
--mirror
, for the purpose of having a backup / public copy of my repository.If you run
it does not only flag the remote as mirror (which is what I wanted for pushes), but also configures
remote.<mirror>.fetch
option for the mirror to+refs/*:refs/*
, which means that all of your branches suddenly "track" your mirror repository and any attempt to create a tracking branch is going to fail.(As an added bonus, running
git fetch <mirror>
is going to overwrite all your refs with old ones from your backup repo.)The solution that seems to fix this issue is setting
remote.<mirror>.fetch
to:
(which, I hope, means "never fetch anything"). This apparently fixes the tracking issue and eliminates the deadly fetch.这里提到的其他修复都不适合我。最终工作的是这样的:
运行上面的代码后,尽管 git 抱怨,它最终还是创建了一个本地分支
test
但没有上游集。现在,我打开
.git/config
文件(其中没有任何分支test
的记录)并手动添加以下内容:之后一切正常。
None of the other fixes mentioned here worked for me. The one that ended up working was this:
After running the above, even though git complained, it did end up creating a local branch
test
but no upstream set.Now, I opened the
.git/config
file (which did not have any record of a branchtest
) and added the following manually:After which everything worked fine.
我遇到了这样的情况,但我不知道怎么办。 gitbranch-av 的列表只显示了我关心的分支的一个远程跟踪分支(origin/dev)。
我修复它的方法是使用十六进制提交哈希而不是
origin/dev
:当我使用
-u
进行推送时,Git 说Branch dev set up跟踪来自原点的远程分支开发。
随后的拉取和推送按我的预期工作。I got in a situation like this, but I do not know how. The listing from
git branch -av
showed me only a single remote tracking branch for the branch I cared about (origin/dev
).What I did to fix it was to use the hexadecimal commit hash instead of
origin/dev
:When I did the push with
-u
Git saidBranch dev set up to track remote branch dev from origin.
Subsequent pulls and pushes worked as I expected.