重命名git标记会导致不一致

art*_*nig 19 git git-tag

用git标签"1.0"重命名为"1.5"后

git tag 1.5 1.0
git tag -d 1.0
git push origin :refs/tags/1.0
Run Code Online (Sandbox Code Playgroud)

我的git存储库似乎处于不一致状态.这是git describe输出:

warning: tag '1.0' is really '1.5' here
1.0-97-g88085b2
Run Code Online (Sandbox Code Playgroud)

它应该1.5-...现在回来

git fsck --tags输出:

Checking object directories: 100% (256/256), done.
tagged commit aad9477bba4bcf44ea34ea9693aeffc98527ff01 (1.0) in b96ce67583239e198f9e2aff5175176d65779044
Checking objects: 100% (3975/3975), done.
Run Code Online (Sandbox Code Playgroud)

如何删除已删除标记的悬空引用?这是重命名标签的正确方法吗?

Lou*_*uis 28

几分钟前我遇到了同样的问题.已经提出的答案都没有涉及真正的问题,即消除了消息warning: tag 'foo' is really 'bar' here并且git describe只是列出了标签的新名称.在我的情况下,这一点尤其重要,因为我的构建系统使用git describe记录到构建中用于构建的源.

复制问题

我可以这样做来复制这个问题:

$ git tag foo --annotate -m"original message"
$ git tag bar foo
$ git tag -d foo
$ git describe 
warning: tag 'foo' is really 'bar' here
foo
Run Code Online (Sandbox Code Playgroud)

(--annotate上面的标志是多余的,因为-m暗示--annotate,但我已将它包含在内以供强调.)我试图用轻量级标签复制问题,但无法这样做.因此,为了复制问题,需要注释.

解决问题

其中一些涉及推动已经被推动的东西,但我发现自己与David Culp达成协议时:

然而,有时候,不准确(杂乱)历史的长期痛苦是不值得的,短期的痛苦是值得的.

一旦你坚持了warning: tag 'foo' is really 'bar' here,那么你必须做到:

$ git tag bar bar -m"original message" --force
$ git describe 
bar
Run Code Online (Sandbox Code Playgroud)

如果消息需要更改,请根据需要进行调整.

如果旧标签已被推送,则删除旧标签:

$ git push origin :refs/tags/foo
Run Code Online (Sandbox Code Playgroud)

要更新新标记(如果已经推送):

$ git push origin refs/tags/bar
Run Code Online (Sandbox Code Playgroud)

避免问题

首先要避免这个问题,你必须创建bar:

$ git tag bar foo -m"original message"
Run Code Online (Sandbox Code Playgroud)