为什么git fetch没有获取任何标签? [英] Why is git fetch not fetching any tags?

查看:1321
本文介绍了为什么git fetch没有获取任何标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个包含几个提交和一些标签的沙箱git仓库,一个轻量级标签和一个标签:

  > mkdir one; CD一个; git init 

>触摸a.txt; git add a.txt; git commit -ma.txt

>触摸b.txt; git add b.txt; git commit -mb.txt
> git标记灯

>触摸c.txt; git add c.txt; git commit -mc.txt
> git tag -a annot -mannot

我现在创建第二个存储库并从第一个存储库:

 > mkdir二; cd二; git init 

> git remote添加一个< ...&one
> git获取一个master
remote:计数对象:9,完成。
remote:压缩对象:100%(7/7),完成。
remote:合计9(增量2),重用0(增量0)
开箱对象:100%(9/9),完成。
从< ...> / one
*分支主控 - > FETCH_HEAD
* [新分支] master - > one / master

为什么没有任何标签被提取?我预计他们会根据 git fetch

lockquote

默认情况下,还会提取指向要读取的历史记录的任何标记;它的作用是获取指向您感兴趣的分支的标签。 更新后的解析方案更新与新的有趣的信息位。我把它放在一个shell脚本中以便测试:

  mkdir ttwo&& cd ttwo&& git init&& git remote添加一个文件:// [path] 

(然后删除 ttwo )。



因此,下面的每个测试运行在新的空 ttwo 。我在这里也使用Git 2.10.1,但与2.11应该没有太大的区别(虽然与Git 1.7相比有明显的不同,它仍然在某些Linux发行版中运行......)。

首先,让我们 git fetch with no refspecs:

  $ git fetch one 
remote:计数对象:8,完成。
remote:压缩对象:100%(6/6),完成。
remote:合计8(delta 1),重用0(delta 0)
开箱对象:100%(8/8),完成。
从file:// [path]
* [new branch] master - > one / master
* [new tag] annot - >注释
* [新标签]指示灯 - > light

这是Git版本2.10.1,两个存储库位于同一台机器上, file:/// home / ... / home /...。两者都会根据需要提取( rm -rf texp2 ),然后拿起这两个标签。现在让我们用单一的refspec master 。从这里开始,我将省略 remote: From:东西,只显示分支和/或标签获得更新:

$ $ p $ code $ git fetch one master
[snip]
* branch master - > FETCH_HEAD
* [新分支] master - > one / master

如果我们使用 master:master ,它需要添加 - update-head-ok

  $ git fetch one --update-head-ok master:master 
* [new branch] master - > master
* [new tag] annot - > annot
* [new branch] master - > one / master
* [新标签] light - >轻



,现在我们得到标签!

如果我们获取 master 但将其写入 refs / remotes / origin / master

  $ git fetch one master:refs / remotes / origin / master 
* [new branch] master - > origin / master
* [new tag] annot - > annot
* [new branch] master - > one / master
* [新标签] light - >轻



有一种模式正在出现:我们必须写一些本地ref(s)



让我们把 master 取到 x dark (我试过 foo bar code>但不起作用,因为 foo 不存在于回购一中):

  $ git fetch one master:x light:dark 
* [new branch] master - > x
* [新标签] light - >暗
* [新标签] annot - >注释
* [新标签]指示灯 - > light
* [new branch] master - > one / master

现在让我们将 master ,我们知道独立运行失败,但是获取 light dark

  $ git获取一个主灯:dark 
*分支主控 - > FETCH_HEAD
* [新标签]指示灯 - >暗
* [新标签] annot - >注释
* [新标签]指示灯 - > light
* [new branch] master - > one / master

最后一个测试:

  $ git获取一个主灯光
*分支主控 - > FETCH_HEAD
*标签指示灯 - > FETCH_HEAD
* [新分支] master - > one / master

这并没有写入我们的标签,只写入 FETCH_HEAD ,再加上通常的机会主义远程追踪分支更新。

底线似乎是,当给出明确的参考时,我们必须写至少有一个地方参考。使用 no 访问refspecs可以工作,因为它使用配置文件中的默认refspecs以及默认标记。获取写入本地ref的一些refspec(s)。获取一些只写入 FETCH_HEAD 的refspec失败。这看起来像一个bug,但不清楚Git中代码的意图是什么,而Git的标签更新代码是非常曲折的。


I have created a sandbox git repository containing a few commits and a couple of tags, one lightweight and one annotated:

> mkdir one; cd one; git init

> touch a.txt; git add a.txt; git commit -m"a.txt"

> touch b.txt; git add b.txt; git commit -m"b.txt"
> git tag light

> touch c.txt; git add c.txt; git commit -m"c.txt"
> git tag -a annot -m"annot"

I now create a second repository and fetch from the first:

> mkdir two; cd two; git init

> git remote add one <...>/one
> git fetch one master
remote: Counting objects: 9, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 9 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (9/9), done.
From <...>/one
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> one/master

Why have neither of the tags been fetched? I expected they would be, based on the documentation for git fetch:

By default, any tag that points into the histories being fetched is also fetched; the effect is to fetch tags that point at branches that you are interested in.

解决方案

Updated with new interesting informational bits. I put this into a shell script for easy testing:

mkdir ttwo && cd ttwo && git init && git remote add one file://[path]

(and then I remove ttwo after running a test).

Hence each test below is run in the new empty ttwo. I am also using Git 2.10.1 here, but there should be no significant differences with 2.11 (while there are definitely significant differences compared with Git 1.7, which is still shipping with certain Linux distributions...).

First, let's git fetch with no refspecs:

$ git fetch one
remote: Counting objects: 8, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 8 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (8/8), done.
From file://[path]
 * [new branch]      master     -> one/master
 * [new tag]         annot      -> annot
 * [new tag]         light      -> light

This is with Git version 2.10.1, with both repositories on the same machine, and using either file:///home/... or /home/.... Both fetches (rm -rf texp2 in between as needed) picked up both tags.

Now let's run it with the single refspec master. From here on I'll leave out the remote: through From: stuff, just show what branches and/or tags get updated:

$ git fetch one master
[snip]
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> one/master

Here's what happens if we use master:master, which requires adding --update-head-ok:

$ git fetch one --update-head-ok master:master
 * [new branch]      master     -> master
 * [new tag]         annot      -> annot
 * [new branch]      master     -> one/master
 * [new tag]         light      -> light

Aha, now we get tags!

Here's what happens if we fetch master but write it to refs/remotes/origin/master:

$ git fetch one master:refs/remotes/origin/master
 * [new branch]      master     -> origin/master
 * [new tag]         annot      -> annot
 * [new branch]      master     -> one/master
 * [new tag]         light      -> light

There is a pattern emerging: we have to write to some local ref(s)

Let's fetch master to x and light to dark (I tried foo to bar but that doesn't work because foo does not exist in repo one):

$ git fetch one master:x light:dark
 * [new branch]      master     -> x
 * [new tag]         light      -> dark
 * [new tag]         annot      -> annot
 * [new tag]         light      -> light
 * [new branch]      master     -> one/master

Now let's fetch master to nothing, which we know fails standalone, but fetch light to dark:

$ git fetch one master light:dark
 * branch            master     -> FETCH_HEAD
 * [new tag]         light      -> dark
 * [new tag]         annot      -> annot
 * [new tag]         light      -> light
 * [new branch]      master     -> one/master

And one last test:

$ git fetch one master light
 * branch            master     -> FETCH_HEAD
 * tag               light      -> FETCH_HEAD
 * [new branch]      master     -> one/master

This did not write to our tags, only to FETCH_HEAD, plus the usual opportunistic remote-tracking branch update.

The bottom line appears to be that, when giving explicit refspecs, we must write at least one local ref. Fetching with no refspecs works, because that uses the default refspecs in the config file plus the default tags. Fetching with some refspec(s) that write to a local ref works. Fetching with some refspec(s) that only write to FETCH_HEAD fails. This seems like a bug, but it's not clear what the intent of the code in Git is, and Git's tag update code is horribly twisty.

这篇关于为什么git fetch没有获取任何标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆