“git fetch --tags”是否有效? 包括“git fetch”?
一个很好且简单的问题 - “git fetch”的功能是 git fetch --tags 的严格子集吗?
也就是说,如果我运行 git fetch --tags ,是否有理由立即运行 git fetch ?
git pull
和 git pull --tags
怎么样? 同样的情况?
A nice and simple question - is the function of "git fetch" a strict sub-set of git fetch --tags
?
I.e. if I run git fetch --tags
, is there ever a reason to immediately run git fetch
straight afterward?
What about git pull
and git pull --tags
? Same situation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
注意:从 git 1.9/2.0 (Q1 2014) 开始),
git fetch --tags
除了在不使用该选项的情况下通过同一命令行获取的内容之外,还获取标签。仅获取标签:
详细信息:
请参阅 迈克尔·哈格蒂 (mhagger):
自 Git 2.5(2015 年第 2 季度)以来,
git pull --tags
更加强大:请参阅提交 19d122b,作者:Paul Tan (
pyokagan
),2015 年 5 月 13 日。(由 Junio C Hamano --
gitster
-- 合并于 提交 cc77b99,2015 年 5 月 22 日)使用 Git 2.11+(2016 年第 4 季度)
git fetch
速度更快。请参阅 提交 5827a03(2016 年 10 月 13 日),作者:杰夫·金 (
peff
)。(由 Junio C Hamano --
gitster
-- 合并于 提交 9fcd144,2016 年 10 月 26 日)这仅适用于以下情况:
Git 2.21(2019 年 2 月)似乎在 config
remote.origin.fetch
为 < em>不是默认的 ('+refs/heads/*:refs/remotes/origin/*'
)Git 2.24 (Q4 2019) 添加了另一项优化。
请参阅 提交 b7e2d8b(2019 年 9 月 15 日),作者:铃木雅也 (
draftcode
)。(由 Junio C Hamano --
gitster
-- 合并于 提交 1d8b0df,2019 年 10 月 7 日)Note: starting with git 1.9/2.0 (Q1 2014),
git fetch --tags
fetches tags in addition to what are fetched by the same command line without the option.To fetch only tags:
In details:
See commit c5a84e9 by Michael Haggerty (mhagger):
Since Git 2.5 (Q2 2015)
git pull --tags
is more robust:See commit 19d122b by Paul Tan (
pyokagan
), 13 May 2015.(Merged by Junio C Hamano --
gitster
-- in commit cc77b99, 22 May 2015)With Git 2.11+ (Q4 2016)
git fetch
is quicker.See commit 5827a03 (13 Oct 2016) by Jeff King (
peff
).(Merged by Junio C Hamano --
gitster
-- in commit 9fcd144, 26 Oct 2016)That applies only for a situation where:
Git 2.21 (Feb. 2019) seems to have introduced a regression when the config
remote.origin.fetch
is not the default one ('+refs/heads/*:refs/remotes/origin/*'
)Git 2.24 (Q4 2019) adds another optimization.
See commit b7e2d8b (15 Sep 2019) by Masaya Suzuki (
draftcode
).(Merged by Junio C Hamano --
gitster
-- in commit 1d8b0df, 07 Oct 2019)注意:此答案仅对 git v1.8 及更早版本有效。
大部分内容已在其他答案和评论中说过,但这里有一个简洁的解释:
git fetch
获取所有分支头(或所有由remote.fetch 配置选项指定的分支头)、它们所需的所有提交以及可从这些分支访问的所有标记。 在大多数情况下,所有标签都可以通过这种方式访问。简介: 如果您确实想完全保持最新状态,并且仅使用 fetch,则必须同时执行这两项操作。
它也不是“慢两倍”,除非您指的是在命令行上键入,在这种情况下别名可以解决您的问题。 发出这两个请求基本上没有任何开销,因为它们请求不同的信息。
Note: this answer is only valid for git v1.8 and older.
Most of this has been said in the other answers and comments, but here's a concise explanation:
git fetch
fetches all branch heads (or all specified by the remote.fetch config option), all commits necessary for them, and all tags which are reachable from these branches. In most cases, all tags are reachable in this way.git fetch --tags
fetches all tags, all commits necessary for them. It will not update branch heads, even if they are reachable from the tags which were fetched.Summary: If you really want to be totally up to date, using only fetch, you must do both.
It's also not "twice as slow" unless you mean in terms of typing on the command-line, in which case aliases solve your problem. There is essentially no overhead in making the two requests, since they are asking for different information.
我自己来回答这个问题。
我已经确定是有区别的。 “git fetch --tags”可能会引入所有标签,但它不会引入任何新的提交!
事实证明,必须这样做才能完全“最新”,即在没有合并的情况下复制“git pull”:
这是一种耻辱,因为它慢了一倍。 如果只有“git fetch”有一个选项可以做它通常做的事情并引入所有标签。
I'm going to answer this myself.
I've determined that there is a difference. "git fetch --tags" might bring in all the tags, but it doesn't bring in any new commits!
Turns out one has to do this to be totally "up to date", i.e. replicated a "git pull" without the merge:
This is a shame, because it's twice as slow. If only "git fetch" had an option to do what it normally does and bring in all the tags.
这里的一般问题是
git fetch
将获取+refs/heads/*:refs/remotes/$remote/*
。 如果这些提交中有任何一个具有标签,那么这些标签也将被获取。 但是,如果远程上的任何分支都无法访问某些标签,则不会获取它们。--tags
选项将 refspec 切换为+refs/tags/*:refs/tags/*
。 您可以要求git fetch
来获取两者。 我很确定只需执行 git fetch && git fetch -t 您将使用以下命令:如果您想将此设置为该存储库的默认值,您可以向默认提取添加第二个 refspec:
这将添加第二个
fetch =此遥控器的
行。.git/config
中的我花了一段时间寻找处理这个项目的方法。 这就是我想出来的。
就我而言,我想要这些功能
refs/*:refs/*
+
覆盖本地分支和标签> 在 refspec 之前-u
-p
-f
>The general problem here is that
git fetch
will fetch+refs/heads/*:refs/remotes/$remote/*
. If any of these commits have tags, those tags will also be fetched. However if there are tags not reachable by any branch on the remote, they will not be fetched.The
--tags
option switches the refspec to+refs/tags/*:refs/tags/*
. You could askgit fetch
to grab both. I'm pretty sure to just do agit fetch && git fetch -t
you'd use the following command:And if you wanted to make this the default for this repo, you can add a second refspec to the default fetch:
This will add a second
fetch =
line in the.git/config
for this remote.I spent a while looking for the way to handle this for a project. This is what I came up with.
In my case I wanted these features
refs/*:refs/*
+
before the refspec-u
-p
-f
在大多数情况下, git fetch 应该执行您想要的操作,即“从远程存储库获取任何新内容并将其放入本地副本中,而不合并到本地分支”。
git fetch --tags
正是这样做的,只不过它除了新标签之外什么也得不到。从这个意义上说, git fetch --tags 绝不是 git fetch 的超集。 事实上恰恰相反。
当然,
git pull
只不过是git fetch的包装器; git 合并
。 建议您在跳转到git pull
之前习惯于进行手动git fetch
和git merge
操作,因为这对您有帮助首先了解 git pull 正在做什么。也就是说,这种关系与 git fetch 完全相同。
git pull
是git pull --tags
的超集。In most situations,
git fetch
should do what you want, which is 'get anything new from the remote repository and put it in your local copy without merging to your local branches'.git fetch --tags
does exactly that, except that it doesn't get anything except new tags.In that sense,
git fetch --tags
is in no way a superset ofgit fetch
. It is in fact exactly the opposite.git pull
, of course, is nothing but a wrapper for agit fetch <thisrefspec>; git merge
. It's recommended that you get used to doing manualgit fetch
ing andgit merge
ing before you make the jump togit pull
simply because it helps you understand whatgit pull
is doing in the first place.That being said, the relationship is exactly the same as with
git fetch
.git pull
is the superset ofgit pull --tags
.工作得很好,它只会获取新标签,而不会获取任何其他代码库。
works just fine, it will only get new tags and will not get any other code base.