Git:从命名远程获取和从 URL 获取有什么区别? [英] Git: What's the difference between fetching from named remote and fetching from a URL?
问题描述
假设我从路径 /path/to/repo
克隆一个 git 存储库.原始存储库将是一个名为origin"的远程存储库.我可以使用命令 git fetch origin
从原点获取对象.这将从远程原点"检索所有对象,包括所做的任何分支.
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 command git fetch origin
. This will retrieve all the objects from the remote "origin", including any branches made.
奇怪的是,如果我使用命令 git fetch/path/to/repo
从同一个存储库中显式获取数据,我似乎会检索所有提交对象,但不会检索任何分支.
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.
这是为什么呢?在这两种情况下,我做的事情不是完全相同吗?Git 的行为怎么会如此不同?
Why is that? Am I not doing exactly the same thing in both cases? How can Git's behavior be so different?
推荐答案
命名远程使用他们的配置,当获取远程时,他们设置 refspec
架构:
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/*
基本上:git fetch <path><来源>:<目的地>
.目的地在这里很重要,因为它是存储远程 HEAD 和分支指针的地方.
Basically: git fetch <path> <source>:<destination>
. And the destination is important here because it's where the remote HEAD and branches pointer are stored.
通过执行 git fetch/path/to/repo
,您无需设置任何 refspec.因此,它只获取提交,而不是对象,因为没有指示 git
获取和存储它们.
By doing git fetch /path/to/repo
, you don't set any refspec. As so, it only fetches the commits, not the objects because git
hasn't been instructed to get and store them.
这里可能有一些细节或命名约定不正确,请随时编辑.但是全局的想法应该是正确的
这篇关于Git:从命名远程获取和从 URL 获取有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!