如果 git 标签在远程更改,则 git fetch 不会在本地更新它。这是一个错误吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8432953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:26:56  来源:igfitidea点击:

If a git tag changes on remote, a git fetch does not update it locally. Is this a bug?

git

提问by donatello

I fixed it for my repo by deleting the local tag and then doing a git fetch. This brought the updated tag.

我通过删除本地标签然后执行 git fetch 为我的 repo 修复了它。这带来了更新的标签。

Is there are "right" way to update tags that may have changed on the remote? This is a simple tag, not signed or anything, created with "git tag "

是否有“正确”的方法来更新遥控器上可能已更改的标签?这是一个简单的标签,没有签名或任何东西,用“git tag”创建

回答by VonC

Make sure you fetch all the tags (through git fetch --tags), to get allthe tags and not just ones referencing commits reachable from the branch heads.

确保获取所有标签(通过git fetch --tags),以获取所有标签,而不仅仅是引用可从分支头访问的提交的标签。

Those (fetched) tags are annotated ones (and usually not lightweight), and if you add deleted one on the local repo, they will just pop back after the fetch.

那些(提取的)标签是带注释的(通常不是轻量级的),如果您在本地存储库中添加已删除的标签,它们将在提取后弹出。

However, if you have deleted a lightweight one, then you need to recreate it locally: a lightweight tag isn't usuallypushed or fetched to/from a remote repo.

但是,如果您删除了一个轻量级标签,那么您需要在本地重新创建它:通常不会向/从远程存储库推送或提取轻量级标签。

Note that starting git 1.9/2.0 (Q1 2014), git fetch --tagswill fetch everything (like git fetch), plus the tags. See "Does “git fetch --tags” include “git fetch”?".

请注意,从 git 1.9/2.0(2014 年第一季度)开始,git fetch --tags将获取所有内容(如git fetch),以及标签。请参阅““ ”是否git fetch --tags包括“ git fetch”?”。

Again, fetch "everything" means annotated and lightweight (if those lightweight tags were previously pushed).

同样,获取“一切”意味着带注释和轻量级(如果这些轻量级标签以前被推送)。



As noted below in biocyberman's answer, if you want to fetch tags from allremotes (not just the default remote named 'origin'), you need to add the --alloption.

正如下面biocyberman回答中所述,如果您想从所有遥控器(不仅仅是名为“ origin”的默认遥控器)获取标签,则需要添加--all选项

git fetch --tags --all

回答by yucer

I think the right way is:

我认为正确的方法是:

  git fetch origin --tags --force

You should avoid to have a branch with the same tag name, because the checkout prioritizes the branch and you can feel like the tag was not updated. Maybe git should have a warning in this case, something like:

您应该避免使用具有相同标签名称的分支,因为结帐会优先考虑该分支,并且您会感觉标签没有更新。也许 git 在这种情况下应该有一个警告,比如:

You have updated a tag that differs now from a branch of the same name. The reference to "tagname" became ambiguous.

您更新了一个与同名分支不同的标签。对“标记名”的引用变得模棱两可。

回答by manojlds

What you have said is the right way and that is what the git tagmanual recommends ( actually, it says, don't change the tags on the remote repo unless the world is coming to an end):

你所说的是正确的方法,这就是git tag手册推荐的(实际上,它说,除非世界末日,否则不要更改远程仓库上的标签):

git tag -d X
git fetch origin tag X

回答by Robert Siemer

In fact git fetch --tagsis enough to let git overwrite lightweight and annotated tags by remote tags of either kind. You can consider it a documentation bug for not mentioning that.

事实上git fetch --tags,足以让 git 通过任何一种远程标签覆盖轻量级和带注释的标签。您可以将其视为未提及的文档错误。

Local tags with names which have no equivalent on the remote will be left alone with this command.

此命令将保留名称在远程上没有等效名称的本地标签。

Tested with git version 2.7.4.

使用 git 版本 2.7.4 测试。

回答by biocyberman

In case one has multiple upstreams:

如果一个有多个上游:

git --version
git version 2.11.1 
git fetch --tags --all

without the --alloption, I could not fetch the tags from the upstream whose name is not "upstream".

如果没有该--all选项,我将无法从名称不是“上游”的上游获取标签。

回答by dbkaplun

I don't think it's a bug. Though you shouldn't change tags, if one changes upstream, this will update the tag on your repo:

我不认为这是一个错误。虽然您不应该更改标签,但如果上游发生更改,这将更新您的 repo 上的标签:

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