git 如何摆脱“会破坏现有标签”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/58031165/
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-19 13:17:44  来源:igfitidea点击:

How to get rid of "would clobber existing tag"

git

提问by Skeeve

I'm using git in VSCodium and each time I try to pull git is complaining.

我在 VSCodium 中使用 git,每次我尝试拉 git 时都在抱怨。

Looking into the log I see

查看我看到的日志

> git pull --tags origin master
From https://github.com/MY/REPO
 * branch            master     -> FETCH_HEAD
 ! [rejected]        latest     -> latest  (would clobber existing tag)
   9428765..935da94  master     -> origin/master

Doing the command with --forcehelps until the next time.

--force在下一次之前使用help 执行命令。

It's unclear to me what's going wrong here. What happened and how can I resolve this issue?

我不清楚这里出了什么问题。发生了什么,我该如何解决这个问题?

I mean: Besides trashing my local repo and cloning again.

我的意思是:除了破坏我的本地仓库并再次克隆。

回答by Tuan Tran

you should update your local tags with remote tags

你应该用远程标签更新你的本地标签

git fetch --tags -f

git fetch --tags -f

then push again

然后再推

回答by Vlad274

Since you say it's unclear what's going wrong, I assume you're not using that tag for anything and you just want to do your own work.

由于您说不清楚出了什么问题,我假设您没有将该标签用于任何事情,而您只想做自己的工作。

Turn off this setting:

关闭此设置:

enter image description here

在此处输入图片说明

Now you're all set.

现在你已经准备好了。



Detailed explanation:

详细解释:

Tags are just references to specific commits (just like branch names). The main difference is that git(as far as I know) assumes tags will not change, where branches are expected to be updated.

标签只是对特定提交的引用(就像分支名称一样)。主要区别在于git(据我所知)假设标签不会改变,分支预计会被更新。

So, the "error" is that you have in your local a tag called latestpointing to commit X - but the remote has a tag called latestpointing to commit Y. If you apply the change from the remote you will overwrite your local tag.

因此,“错误”是您在本地有一个名为latest指向提交 X的标记- 但远程有一个名为latest指向提交 Y 的标记。如果您从远程应用更改,您将覆盖本地标记。

VSCode will pull all tags by default, thus you get the error.

默认情况下,VSCode 会拉取所有标签,因此您会收到错误消息。

There isn't anything wrongwith having a "moving" tag like latest, that just isn't something VSCode takes into account (personal opinion).

有一个“移动”标签没有任何问题,比如latest,这不是 VSCode 考虑到的(个人意见)。



Alternatively, you can avoid the issue by using the command line and manually entering the git pullcommand. Specifically, you need to omit --tagsto skip this step of the process.

或者,您可以通过使用命令行并手动输入git pull命令来避免该问题。具体来说,您需要省略--tags以跳过该过程的步骤。

If you do this, your tags will not be updated - but I don't think is a concern here.

如果您这样做,您的标签将不会更新 - 但我认为这不是问题。