gpt4 book ai didi

git - 为什么 "git describe"在我干净的 git repo 副本上显示旧标签版本?

转载 作者:行者123 更新时间:2023-12-03 18:35:57 26 4
gpt4 key购买 nike

一些背景:

我目前有两个本地 git 存储库,它们指向同一个源/主项目。我有两个 git repos 的原因是我有一个干净的主副本,我可以在需要时随时使用,还有一个副本可以在我的沙箱中应用更改、提交等。这可能有点矫枉过正,但有一些优点对我个人来说,有一个重复的本地 git 副本。

一位同事最初为 1.0.2 创建了一个轻量级标签,但我们将其删除并重新标记为具有相同编号的带注释版本。他们通过 git push 将更改提交到远程仓库。我在我的本地 git 实例上 pull 下了最新的更改。

我们的标签如下:

release-1.0.0
release-1.0.1
release-1.0.2

问题:

这是我无法弄清楚的问题。当我运行“ git describe”时,我的沙箱存储库显示了最新的标签版本(release-1.0.2)。这是我所期望的。但是,当我执行“ git describe”时,我只从其中提取的干净存储库副本显示旧标签(release-1.0.1)。我验证了两者都指向原始主人。我做了更多的研究,发现了一个 overstack solution这指向我运行“git cat-file -t”。这是我注意到的不同之处:
git cat-file -t release-1.0.1 --> tag 
git cat-file -t release-1.0.2 --> commit

为什么当我运行“ git describe ”时,我的干净副本存储库会显示旧的标签版本,这与我的沙箱存储库不同?如果我在干净的 repo 副本上运行“ git describe --tags”,我可以确认我可以看到 release-1.0.2 列出。

最佳答案

A co-worker originally created a lightweight tag for 1.0.2, but we deleted it and re-tagged it as an annotated version with the same number. They committed the change via git push to the remote repo. I pulled down the latest changes on both my local git instances.



除非你使用 --tags旗帜, git describe只关心 annotated (与 lightweight 相反)标签。这里, git cat-file 的输出表示你还有旧的 release-1.0.2沙箱存储库中的轻量级标签。问题在于,默认情况下, git pull本身不会获取较新的、带注释的同名标签并用它覆盖旧的、轻量级的标签。

要解决这个问题,首先通过运行在本地删除轻量级标签
git tag -d release-1.0.2

在您的沙箱存储库中,然后运行
git fetch

(或 git pull ,如果您知道自己在做什么)。新款 release-1.0.2带注释的标签将取代旧的轻量级标签。您可以通过运行 git describe 来确保这一点。或者
git cat-file -t release-1.0.2

现在应该输出 tag (不是 commit )。

关于git - 为什么 "git describe"在我干净的 git repo 副本上显示旧标签版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32209616/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com