为什么 git branch -t 失败并显示“不跟踪:不明确的信息”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1395053/
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
Why does git branch -t fail with "Not tracking: ambiguous information"?
提问by che
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 sourceseems to somehow search for branches to track and throws me out because it finds lessmore 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?
谁能告诉我发生了什么以及如何解决它?
采纳答案by che
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.
知道了!问题是我之前设置了一个远程--mirror
,目的是拥有我的存储库的备份/公共副本。
If you run
如果你跑
git remote add --mirror <name> <url>
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.
它不仅将远程标记为镜像(这是我想要的推送),而且还remote.<mirror>.fetch
为镜像配置选项 to +refs/*:refs/*
,这意味着您的所有分支突然“跟踪”您的镜像存储库以及任何创建跟踪分支的尝试会失败。
(As an added bonus, running git fetch <mirror>
is going to overwrite all your refs with old ones from your backup repo.)
(作为一个额外的好处,运行git fetch <mirror>
将用备份仓库中的旧引用覆盖所有引用。)
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.
似乎解决这个问题的解决方案是设置remote.<mirror>.fetch
为:
(我希望,这意味着“从不获取任何东西”)。这显然解决了跟踪问题并消除了致命的获取。
回答by Matthew Phillips
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.
当我有两个具有相同(默认)获取模式 ( fetch = +refs/heads/*:refs/remotes/origin/*
) 和相同分支的远程存储库时,我也看到了这一点。
I still haven't worked out how to fix it properly, since I want to continue to push/pull to both repo's, but manually adding the info to the project's .git/config
works, e.g.:
我仍然没有想出如何正确修复它,因为我想继续推/拉两个仓库,但手动将信息添加到项目的.git/config
工作中,例如:
[branch "mybranch"]
remote = origin
merge = refs/heads/mybranch
回答by VonC
because it finds less than one
因为它找到的少于一个
Nope: because it finds morethan one matching remote branch, which means the function remote_find_tracking()
returns more than one tracking branch for a given local branch ref.
不:因为它找到了多个匹配的远程分支,这意味着该函数remote_find_tracking()
为给定的本地分支引用返回多个跟踪分支。
Is some_remote_branch
not alreadytracked 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. )
是some_remote_branch
不是已经被当地的一个分支跟踪?
(agit config -l
将允许您检查您当前已设置的内容)。
(agit branch -r
还可以帮助列出您当前的远程跟踪分支。)
remote branches, which I thought are something different that remote-tracking branches.
远程分支,我认为与远程跟踪分支不同。
Wrong, as illustrated by this thread:
错误,如此线程所示:
remote-branches are the "real" remote-tracking-branches. You don't commit to them locally, they are essentially read-only copies of exactly what is happening in a remote repository.
If you try to 'git-checkout' a remote-tracking branch, you will get a detached HEAD.Local branch:
A branch to which you may commit changes. Optionally, the branch can be configured to "follow" one of your remote-tracking branches. This means that a 'git-pull
' without arguments (when your local branch is checked out), will automatically 'git-fetch
' and then 'git-merge
' the remote-tracking branch.
远程分支是“真正的”远程跟踪分支。您不必在本地提交它们,它们本质上是远程存储库中正在发生的事情的只读副本。
如果您尝试 'git-checkout' 远程跟踪分支,您将获得一个分离的 HEAD。本地分支:
您可以向其提交更改的分支。或者,可以将分支配置为“跟随”您的远程跟踪分支之一。这意味着git-pull
不带参数的 ' '(当您的本地分支被检出时)将自动 'git-fetch
' 然后是 'git-merge
' 远程跟踪分支。
Now:
现在:
it's the job of
git-fetch
to update remote-tracking branches with any changes found in the remote repository.Git-pull
runsgit-fetch
and then runs agit-merge
to update the currently-checked-out branch.
git-fetch
使用远程存储库中发现的任何更改更新远程跟踪分支的工作。Git-pull
运行git-fetch
然后运行 agit-merge
来更新当前签出的分支。
The problem is, for git-merge:
问题是,对于 git-merge:
When this happens,
git-merge
must decide whichremote-tracking-branch
to merge into the currently checked out local branch.
You can set whichremote-tracking-branch
will be selected in this situation with the --track option.
--track
sets up a local following branch to refer to a remote's branch, notto the tracking branch
发生这种情况时,
git-merge
必须决定将哪个remote-tracking-branch
合并到当前检出的本地分支中。
您可以remote-tracking-branch
使用 --track 选项设置在这种情况下将选择哪个。
--track
设置本地跟随分支以引用远程分支,而不是跟踪分支
Consider thatremote_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.
考虑remote_find_tracking()
使用单个遥控器和一个 src 填充的 refspec,并在填充其 dst 后返回给定的 refspec,如果为遥控器配置了适当的跟踪,即 git。
/*
* For the given remote, reads the refspec's src and sets the other fields.
*/
int remote_find_tracking(struct remote *remote, struct refspec *refspec);
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 anotherremote branch would make the git-merge
unable to choose which local branch to update/merge with changes of a remote.
可能它认为它已经有一个本地跟随分支匹配some_remote_branch
。你有同名的本地分行吗?
或者,反过来说:您当前的分支有一个名称相似的远程分支,这使其成为 any 的自然候选者git-merge
:尝试使其跟踪另一个远程分支将导致git-merge
无法选择要更新/合并的本地分支遥控器的变化。
回答by amacleod
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
).
我遇到了这样的情况,但我不知道如何。来自的列表git branch -av
只显示了我关心的分支的一个远程跟踪分支 ( origin/dev
)。
What I did to fix it was to use the hexadecimal commit hash instead of origin/dev
:
我为修复它所做的是使用十六进制提交哈希而不是origin/dev
:
git checkout -b dev abc123
git push -u origin dev
When I did the push with -u
Git said Branch dev set up to track remote branch dev from origin.
Subsequent pulls and pushes worked as I expected.
当我用-u
Git进行推送时,说Branch dev set up to track remote branch dev from origin.
后续的拉取和推送按我的预期工作。
回答by GuSuku
None of the other fixes mentioned here worked for me. The one that ended up working was this:
此处提到的其他修复均不适合我。最终工作的是这样的:
$ git branch -t test origin/test
error: Not tracking: ambiguous information for ref refs/remotes/origin/test
After running the above, even though git complained, it did end up creating a local branch test
but no upstream set.
运行上述后,即使 git 抱怨,它最终还是创建了一个本地分支,test
但没有上游集。
Now, I opened the .git/config
file (which did not have any record of a branch test
) and added the following manually:
现在,我打开.git/config
文件(没有任何分支记录test
)并手动添加以下内容:
[branch "test"]
remote = origin
merge = refs/heads/test
After which everything worked fine.
之后一切正常。