“git fetch --tags”是否有效? 包括“git fetch”?

发布于 2024-07-29 06:51:54 字数 198 浏览 5 评论 0原文

一个很好且简单的问题 - “git fetch”的功能是 git fetch --tags 的严格子集吗?

也就是说,如果我运行 git fetch --tags ,是否有理由立即运行 git fetch ?

git pullgit 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

思慕 2024-08-05 06:51:54

注意:从 git 1.9/2.0 (Q1 2014) 开始)git fetch --tags 除了在不使用该选项的情况下通过同一命令行获取的内容之外,还获取标签。

仅获取标签:

git fetch <remote> 'refs/tags/*:refs/tags/*'

详细信息:

请参阅 迈克尔·哈格蒂 (mhagger):

以前,fetch 的“--tags”选项被认为等同于指定 refspec

refs/tags/*:refs/tags/* 
  

在命令行上;
特别是,它导致 remote..refspec 配置被忽略。

但是,在不获取其他引用的情况下获取标签并不是很有用,而除了获取其他引用之外,还能够获取标签非常有用。< br>
因此,更改此选项的语义以执行后者。

如果用户只想获取标签,那么仍然可以指定显式的引用规范:

git fetch ;   '参考/标签/*:参考/标签/*' 
  

请注意,1.8.0.3 之前的文档对于“fetch --tags”行为的这方面内容不明确。
提交f0cb2f1 (2012-12-14) fetch --tags 使文档与旧行为相匹配。
此提交更改了文档以匹配新行为(请参阅 Documentation/fetch-options.txt)。

请求从远程获取所有标签以及正在获取的其他内容


自 Git 2.5(2015 年第 2 季度)以来,git pull --tags 更加强大:

请参阅提交 19d122b,作者:Paul Tan (pyokagan),2015 年 5 月 13 日。
(由 Junio C Hamano -- gitster -- 合并于 提交 cc77b99,2015 年 5 月 22 日)

pull:删除无合并候选情况下的 --tags 错误

441ed41 ("git pull --tags “:错误提示更好的消息。,
2007-12-28,Git 1.5.4+),如果出现以下情况,git pull --tags 将打印不同的错误消息
git-fetch 没有返回任何合并候选:

拉取所有标签没有意​​义;   你可能的意思是: 
        git fetch --标签 
  

这是因为当时,git-fetch --tags 会覆盖任何
配置了 refspec,因此不会有合并候选者。 因此引入错误消息是为了防止混淆。

但是,自从 c5a84e9 (fetch --tags :获取标签除了
其他东西,2013-10-30,Git 1.9.0+),git fetch --tags 还会另外获取标签
任何配置的参考规范。
因此,如果出现任何无合并候选的情况,这并不是因为设置了 --tags 。 因此,这个特殊的错误消息现在已经无关紧要了。

为防止混淆,请删除此错误消息。


使用 Git 2.11+(2016 年第 4 季度)git fetch 速度更快。

请参阅 提交 5827a03(2016 年 10 月 13 日),作者:杰夫·金 (peff)
(由 Junio C Hamano -- gitster -- 合并于 提交 9fcd144,2016 年 10 月 26 日)

fetch:使用“快速”has_sha1_file 用于标记跟随

当从具有许多与我们正在跟踪的分支无关的标签的远程获取时,我们在检查标签指向的对象(我们不会获取!)是否存在时浪费了太多的周期。在我们的存储库中太仔细了。

这个补丁教导 fetch 使用 HAS_SHA1_QUICK 来牺牲
速度的准确性,在我们可能对速度很敏感的情况下
同时重新包装。

以下是所包含的 perf 脚本的结果,该脚本设置了与上述情况类似的情况:

测试 HEAD^ HEAD 
  -------------------------------------------------- -------- 
  5550.4:取11.21(10.42+0.78)0.08(0.04+0.02)-99.3% 
  

这仅适用于以下情况:

  1. 客户端有很多包,导致 reprepare_packed_git() 成本高昂(最昂贵的部分是在未排序的列表中查找重复项,目前该列表是二次的)。
  2. 您需要在服务器端提供大量标签引用作为自动关注的候选者(即客户端没有)。
    每一个都会触发对包目录的重新读取。
  3. 在正常情况下,客户端会自动跟踪这些标签,并且在一次大量提取之后,(2) 将不再成立。
    但是,如果这些标签指向与客户端获取的内容无关的历史记录,那么它永远不会自动关注,并且这些候选者将在每次获取时影响它。

Git 2.21(2019 年 2 月)似乎在 config remote.origin.fetch 为 < em>不是默认的 ('+refs/heads/*:refs/remotes/origin/*')

fatal: multiple updates for ref 'refs/tags/v1.0.0' not allowed

Git 2.24 (Q4 2019) 添加了另一项优化。

请参阅 提交 b7e2d8b(2019 年 9 月 15 日),作者:铃木雅也 (draftcode)
(由 Junio C Hamano -- gitster -- 合并于 提交 1d8b0df,2019 年 10 月 7 日)

fetch:使用oidset保留所需的OID以加快查找速度

git fetch 期间,客户端检查广告标签的 OID 是否已在获取请求的所需 OID 集中。
此检查是通过线性扫描完成的。
对于具有大量引用的存储库,重复此扫描需要 15 分钟以上。

为了加快速度,请为其他引用的 OID 创建一个 oid_set

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:

git fetch <remote> 'refs/tags/*:refs/tags/*'

In details:

See commit c5a84e9 by Michael Haggerty (mhagger):

Previously, fetch's "--tags" option was considered equivalent to specifying the refspec

refs/tags/*:refs/tags/*

on the command line;
in particular, it caused the remote.<name>.refspec configuration to be ignored.

But it is not very useful to fetch tags without also fetching other references, whereas it is quite useful to be able to fetch tags in addition to other references.
So change the semantics of this option to do the latter.

If a user wants to fetch only tags, then it is still possible to specifying an explicit refspec:

git fetch <remote> 'refs/tags/*:refs/tags/*'

Please note that the documentation prior to 1.8.0.3 was ambiguous about this aspect of "fetch --tags" behavior.
Commit f0cb2f1 (2012-12-14) fetch --tags made the documentation match the old behavior.
This commit changes the documentation to match the new behavior (see Documentation/fetch-options.txt).

Request that all tags be fetched from the remote in addition to whatever else is being fetched.


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)

pull: remove --tags error in no merge candidates case

Since 441ed41 ("git pull --tags": error out with a better message.,
2007-12-28, Git 1.5.4+), git pull --tags would print a different error message if
git-fetch did not return any merge candidates:

It doesn't make sense to pull all tags; you probably meant:
      git fetch --tags

This is because at that time, git-fetch --tags would override any
configured refspecs, and thus there would be no merge candidates. The error message was thus introduced to prevent confusion.

However, since c5a84e9 (fetch --tags: fetch tags in addition to
other stuff, 2013-10-30, Git 1.9.0+), git fetch --tags would fetch tags in addition
to any configured refspecs.
Hence, if any no merge candidates situation occurs, it is not because --tags was set. As such, this special error message is now irrelevant.

To prevent confusion, remove this error message.


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)

fetch: use "quick" has_sha1_file for tag following

When fetching from a remote that has many tags that are irrelevant to branches we are following, we used to waste way too many cycles when checking if the object pointed at by a tag (that we are not going to fetch!) exists in our repository too carefully.

This patch teaches fetch to use HAS_SHA1_QUICK to sacrifice
accuracy for speed, in cases where we might be racy with a
simultaneous repack.

Here are results from the included perf script, which sets up a situation similar to the one described above:

Test            HEAD^               HEAD
----------------------------------------------------------
5550.4: fetch   11.21(10.42+0.78)   0.08(0.04+0.02) -99.3%

That applies only for a situation where:

  1. You have a lot of packs on the client side to make reprepare_packed_git() expensive (the most expensive part is finding duplicates in an unsorted list, which is currently quadratic).
  2. You need a large number of tag refs on the server side that are candidates for auto-following (i.e., that the client doesn't have).
    Each one triggers a re-read of the pack directory.
  3. Under normal circumstances, the client would auto-follow those tags and after one large fetch, (2) would no longer be true.
    But if those tags point to history which is disconnected from what the client otherwise fetches, then it will never auto-follow, and those candidates will impact it on every fetch.

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/*')

fatal: multiple updates for ref 'refs/tags/v1.0.0' not allowed

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)

fetch: use oidset to keep the want OIDs for faster lookup

During git fetch, the client checks if the advertised tags' OIDs are already in the fetch request's want OID set.
This check is done in a linear scan.
For a repository that has a lot of refs, repeating this scan takes 15+ minutes.

In order to speed this up, create a oid_set for other refs' OIDs.

苏辞 2024-08-05 06:51:54

注意:此答案仅对 git v1.8 及更早版本有效。

大部分内容已在其他答案和评论中说过,但这里有一个简洁的解释:

  • git fetch获取所有分支头(或所有由remote.fetch 配置选项指定的分支头)、它们所需的所有提交以及可从这些分支访问的所有标记。 在大多数情况下,所有标签都可以通过这种方式访问​​。
  • git fetch --tags 获取所有标签以及它们所需的所有提交。 它不会更新分支头,即使可以从获取的标签访问它们。

简介: 如果您确实想完全保持最新状态,并且仅使用 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.

活雷疯 2024-08-05 06:51:54

我自己来回答这个问题。

我已经确定是有区别的。 “git fetch --tags”可能会引入所有标签,但它不会引入任何新的提交!

事实证明,必须这样做才能完全“最新”,即在没有合并的情况下复制“git pull”:

$ git fetch --tags
$ git fetch

这是一种耻辱,因为它慢了一倍。 如果只有“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:

$ git fetch --tags
$ git fetch

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.

暖树树初阳… 2024-08-05 06:51:54

这里的一般问题是 git fetch 将获取 +refs/heads/*:refs/remotes/$remote/*。 如果这些提交中有任何一个具有标签,那么这些标签也将被获取。 但是,如果远程上的任何分支都无法访问某些标签,则不会获取它们。

--tags 选项将 refspec 切换为 +refs/tags/*:refs/tags/*。 您可以要求git fetch来获取两者。 我很确定只需执行 git fetch && git fetch -t 您将使用以下命令:

git fetch origin "+refs/heads/*:refs/remotes/origin/*" "+refs/tags/*:refs/tags/*"

如果您想将此设置为该存储库的默认值,您可以向默认提取添加第二个 refspec:

git config --local --add remote.origin.fetch "+refs/tags/*:refs/tags/*"

这将添加第二个 fetch =此遥控器的 .git/config 中的 行。


我花了一段时间寻找处理这个项目的方法。 这就是我想出来的。

git fetch -fup origin "+refs/*:refs/*"

就我而言,我想要这些功能

  • 从远程获取所有头和标签,因此使用 refspec 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 ask git fetch to grab both. I'm pretty sure to just do a git fetch && git fetch -t you'd use the following command:

git fetch origin "+refs/heads/*:refs/remotes/origin/*" "+refs/tags/*:refs/tags/*"

And if you wanted to make this the default for this repo, you can add a second refspec to the default fetch:

git config --local --add remote.origin.fetch "+refs/tags/*:refs/tags/*"

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.

git fetch -fup origin "+refs/*:refs/*"

In my case I wanted these features

  • Grab all heads and tags from the remote so use refspec refs/*:refs/*
  • Overwrite local branches and tags with non-fast-forward + before the refspec
  • Overwrite currently checked out branch if needed -u
  • Delete branches and tags not present in remote -p
  • And force to be sure -f
メ斷腸人バ 2024-08-05 06:51:54

在大多数情况下, git fetch 应该执行您想要的操作,即“从远程存储库获取任何新内容并将其放入本地副本中,而不合并到本地分支”。 git fetch --tags 正是这样做的,只不过它除了新标签之外什么也得不到。

从这个意义上说, git fetch --tags 绝不是 git fetch 的超集。 事实上恰恰相反。

当然,git pull只不过是git fetch的包装器; git 合并。 建议您在跳转到 git pull 之前习惯于进行手动 git fetchgit merge 操作,因为这对您有帮助首先了解 git pull 正在做什么。

也就是说,这种关系与 git fetch 完全相同。 git pullgit 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 of git fetch. It is in fact exactly the opposite.

git pull, of course, is nothing but a wrapper for a git fetch <thisrefspec>; git merge. It's recommended that you get used to doing manual git fetching and git mergeing before you make the jump to git pull simply because it helps you understand what git 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 of git pull --tags.

老子叫无熙 2024-08-05 06:51:54
git fetch upstream --tags

工作得很好,它只会获取新标签,而不会获取任何其他代码库。

git fetch upstream --tags

works just fine, it will only get new tags and will not get any other code base.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文