[英]Git - remote branch invisible to local repo, fetch isn't helping
I have a personal git repo on a server ("Server Repo"). 我在服务器上有一个个人git仓库(“服务器仓库”)。 It cannot see a branch on its central remote repo ("Origin") that I pushed from a personal git repo on another computer ("Personal Repo"). 它看不到我从另一台计算机(“个人存储库”)上的个人git存储库推送的中央远程存储库(“原始”)上的分支。
Server Repo (personal repository): 服务器存储库(个人存储库):
$ git branch -a
* master
remotes/origin/master
Origin (central repository): 来源(中央存储库):
$ git branch -a
* master
update
Personal Repo (personal repository): 个人回购(个人存储库):
$ git branch -a
* update
master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/update
On Server Repo, I've tried $ git fetch --all
but all I get is Fetching origin
with no results. 在服务器回购上,我尝试了$ git fetch --all
所有,但是我得到的只是Fetching origin
结果而没有结果。
$ git fetch -v --all
yields: $ git fetch -v --all
收益:
Fetching origin
= [up to date] master -> origin/master
I've never seen this issue before. 我从来没有见过这个问题。 I'm having a lot of issues searching for this problem because all Git Fetch issues seem to assume that the user is doing something wrong. 我在搜索此问题时遇到了很多问题,因为所有Git Fetch问题似乎都假设用户做错了什么。 As far as I can tell, Git is failing to recognize remote branches and I don't know what to do about it. 据我所知,Git无法识别远程分支,我不知道该怎么办。
I've re-cloned from Origin into a new folder and the branches appear as expected then. 我已经从Origin重新克隆到一个新文件夹中,然后分支按预期出现。 I'm not sure what it is about re-cloning a repo from Origin that would get it to work properly. 我不确定从Origin重新克隆一个回购协议是什么,它将使它正常工作。 I have verified that in Server Repo the remote Origin is in fact correct and has the correct path (it's an absolute path on the same machine). 我已经验证了在Server Repo中,远程Origin实际上是正确的并且具有正确的路径(这是同一台计算机上的绝对路径)。
git checkout --track origin/update
The syntax in this answer worked: https://stackoverflow.com/a/1614996/448640 此答案中的语法有效: https : //stackoverflow.com/a/1614996/448640
$ git fetch origin remote_branch_name:local_branch_name
This doesn't answer why I couldn't use the normal command to fetch, but at least it solved the problem. 这不能回答为什么我不能使用普通命令进行提取,但至少可以解决问题。
After performing this version of the command, I have the Origin update branch locally on Server Repo, but when I run git branch -a
I still don't see remotes/origin/update
. 执行此版本的命令后,我在Server Repo上本地拥有Origin更新分支,但是当我运行git branch -a
,仍然看不到remotes/origin/update
。 Still confused. 还是很困惑。
UPDATE 1: 更新1:
Andrew C suggested that I look at my fetch specifications in <repo>/.git/config on Server Repo. Andrew C建议我在服务器存储库的<repo> /。git / config中查看获取规范。 I searched and found an example in the Git docs of what that specification is supposed to be: https://git-scm.com/book/en/v2/Git-Internals-The-Refspec 我搜索并在Git文档中找到了该规范的示例: https : //git-scm.com/book/en/v2/Git-Internals-The-Refspec
My Server Repo config file looked like this before: 我的服务器存储库配置文件如下所示:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = /home/user/repo/project.git
fetch = +refs/heads/master:refs/remotes/origin/master
[branch "master"]
remote = origin
merge = refs/heads/master
Note the line with fetch = +refs/heads/master:refs/remotes/origin/master
. 注意fetch = +refs/heads/master:refs/remotes/origin/master
。 The link to git-scm.com has an example with wildcards like this: fetch = +refs/heads/*:refs/remotes/origin/*
git-scm.com的链接有一个带有通配符的示例,如下所示: fetch = +refs/heads/*:refs/remotes/origin/*
So I changed master
to *
in my fetch directive and now I can see and fetch my branches like normal! 因此,我在fetch指令中将master
更改为*
,现在我可以像平常一样看到并提取我的分支了!
$ git branch -a
update
* master
remotes/origin/master
$ git fetch
From /home/user/repo/project.git
* [new branch] update -> origin/update
$ git branch -a
update
* master
remotes/origin/update
remotes/origin/master
I'm not sure why the fetch spec was incorrect, but I've now answered the question of why I couldn't see my remote branches, and I've solved the problem of obtaining the remote branches. 我不确定为什么提取规范不正确,但是我已经回答了为什么看不到远程分支的问题,并且已经解决了获取远程分支的问题。
Please correct me if I'm wrong, but I am going to guess that because the fetch spec only specified the master
branch, it was ignoring all other branches. 如果我错了,请纠正我,但是我会猜测,因为获取规范仅指定了master
分支,所以它忽略了所有其他分支。 The :
notation command I used to get the remote branch must ignore the fetch spec in the config file. 我用来获取远程分支的:
符号命令必须忽略配置文件中的获取规范。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.