尝试推入 SourceTree 时出现“更新被拒绝,因为标签已存在”

问题描述 投票:0回答:6

尝试通过源树推送时,出现以下错误:

git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree push -v --tags origin refs/heads/master:refs/heads/master 
Pushing to https://[email protected]/repo.git
To https://[email protected]/repo.git
 = [up to date]      master -> master
...
 ! [rejected]        example_tag -> example_tag (already exists)
updating local tracking ref 'refs/remotes/origin/master'
error: failed to push some refs to 'https://[email protected]/repo.git'
hint: Updates were rejected because the tag already exists in the remote.
Completed with errors, see above

据我所知,我没有对此标签进行任何更改。我该如何解决这个问题?

git push atlassian-sourcetree git-tag
6个回答
370
投票

您还应该能够在 git bash 中解决这个问题(单击源树 UI 中的“终端”按钮)。类型:

git pull --tags

如果您有冲突的标签,您可以在命令中包含

-f
选项,以使用远程版本覆盖本地冲突标签。

git pull --tags -f

142
投票

如果您尚未对要保留的标签进行任何本地更改,则可以删除被拒绝的标签,因为它已经存在(在本例中为

example_tag
):

  1. 右键单击标签并选择删除它(请务必取消选中从所有遥控器中删除标签复选框)。
  2. 选择Fetch选项(在本地获取并存储所有标签不必必须启用)。
  3. 您现在应该已经恢复了刚刚删除的标签,并且尝试Push将不再显示该错误消息。

这在 SourceTree 中很常见的原因是因为 Push all Tags 选项默认设置为 on。 (隐藏此错误的另一种方法是取消选中该选项。)


54
投票

git pull --tags
效果非常好,但有时即使使用此命令也会出现错误。错误消息示例:

 ! [rejected]        example_tag      -> example_tag  (would clobber existing tag)

这可以通过命令解决

git pull --tags -f

-f
代表

来源:

https://github.com/concourse/git-resource/issues/233


37
投票

确认 git 推送时,取消选中 UI 底部的

push all tags


29
投票

确保在推送时取消选中“推送所有标签”按钮。


3
投票

在 SourceTree 中,这似乎有效:

  1. 单击“获取”图标
  2. 勾选“获取所有标签”
  3. 点击确定
© www.soinside.com 2019 - 2024. All rights reserved.