Git:从命名远程获取和从URL获取有什么区别? [英] Git: What's the difference between fetching from named remote and fetching from a URL?
问题描述
/ path / to / repo
克隆了一个git仓库。原始存储库将是一个称为原点的远程。我可以使用命令 git fetch origin
从原点获取对象。这将从远程origin中检索所有对象,包括所有制作的分支。 有趣的是,如果我使用命令 git fetch / path / to / repo
,我似乎检索所有提交对象,但没有检索任何分支。
这是为什么?在这两种情况下,我没有做过完全一样的事情吗?如何让Git的行为如此不同?
命名远程使用它们的配置,在其中设置 refspec
schema当这个远程被提取时:
[remoteorigin]
fetch = + refs / heads / *:refs / remotes / origin / *
url = / path / to / repo
$ b $因此,这两种格式是等价的:
git fetch origin
。这里的目的地很重要,因为它是存储远程HEAD和分支指针的地方。
git fetch / path / to /基本上:<$ c $ / b $ b $ / code $ c> git fetch<路径> <信源>:其中目的地>
通过执行
git fetch / path / to / repo
,你不设置任何refspec。因为它只提取提交,而不是对象,因为git
没有被指示获取并存储它们。
这里可能有一些细节或命名约定不正确,请随时编辑。但全球的想法应该是正确的
Suppose I clone a git repository from the path
/path/to/repo
. The original repository will be a remote called "origin". I can fetch objects from the origin with the commandgit fetch origin
. This will retrieve all the objects from the remote "origin", including any branches made.What's curious is that if I explicitly fetch from that same repository with the command
git fetch /path/to/repo
, I appear to retrieve all of the commit objects but not any of the branches.Why is that? Am I not doing exactly the same thing in both cases? How can Git's behavior be so different?
解决方案Named remote use their configuration where they setup a
refspec
schema when this remote is fetched:[remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* url = /path/to/repo
So, these two format are equivalent:
git fetch origin git fetch /path/to/repo +refs/heads/*:refs/remotes/origin/*
Basically:
git fetch <path> <source>:<destination>
. And the destination is important here because it's where the remote HEAD and branches pointer are stored.By doing
git fetch /path/to/repo
, you don't set any refspec. As so, it only fetches the commits, not the objects becausegit
hasn't been instructed to get and store them.There may be some details or naming convention incorrect here, feel free to edit. But the global idea should be correct
这篇关于Git:从命名远程获取和从URL获取有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!