gpt4 book ai didi

git - 为什么 `git describe -dirty` 在描述干净 checkout 时添加 `-dirty` 后缀?

转载 作者:太空狗 更新时间:2023-10-29 12:52:41 24 4
gpt4 key购买 nike

我刚刚发现了 --dirty git describe 的选项看起来它应该做一些非常有用的事情,即在 git describe 的输出中附加一个后缀当工作树变脏时,但在我的某些存储库中情况似乎并非如此:

$ git status
# On branch 8.30
nothing to commit (working directory clean)
$ git describe --dirty
8.30rel-8-g9c1cbdb-dirty

我认为这可能是因为工作目录相对于标记是脏的,但似乎也不是这样:

$ git status
# On branch 1.4
nothing to commit (working directory clean)
$ git describe --tags --dirty --long
1.4rel-0-gfedfe66-dirty

我曾经广泛使用 hg id当我以前use Mercurial并且喜欢它的默认行为是添加 + 的事实它为脏存储库报告的任何提交哈希的后缀,因此一直在寻找 git等效于,但是 git describe --dirty鉴于文档,似乎没有做我期望的事情:

   --dirty[=<mark>]
Describe the working tree. It means describe HEAD and appends
<mark> (-dirty by default) if the working tree is dirty.

我是不是误会了什么--dirty应该这样做,还是我没有正确使用它?

如果有任何不同,所有的 git 存储库都是通过 buckminster 部署的所以不涉及子模块,文件系统是nfs分享。


更新:我发现了一个变通办法,但我完全不知道这可能会带来什么不同。

如果我运行 git diff --quiet HEAD在 repo 协议(protocol)上然后突然git describe按我的预期工作:

$ git status
# On branch 8.30
nothing to commit (working directory clean)
$ git describe --dirty
8.30rel-8-g9c1cbdb-dirty
$ git diff --quiet HEAD
$ git describe --dirty
8.30rel-8-g9c1cbdb

我还发现当git describe将存储库报告为 dirty然后gitk还显示“本地未提交的更改,未 checkin 索引”,然后列出工作目录中的每个文件,但没有针对它们的差异,只有 ---- filename ----行。


进一步更新:由于这一直是个问题,我最终写了一个 git-describe-dirty脚本,首先运行 git describe --dirty但如果它发现存储库变脏,则运行 git update-index -q --refresh在再次尝试并取得第二个结果之前。

在遍历数百个存储库时,使用 git describe-dirty与运行 git update-index -q --refresh ; git describe --dirty 相比,仅运行最初表明它是脏的存储库的索引更新可以节省大量时间。每次。

最佳答案

如果你运行的是 git 1.7.6 或更早版本,你需要在使用 git describe --dirty 之前运行 git update-index --refresh,因为索引可能是陈旧的。您使用 git diff --quiet HEAD 的解决方法是可行的,因为“git diff”是一个瓷器命令,并且可能会更新索引本身。

git commit that fixes this对于 git 1.7.7 描述了问题:

When running git describe --dirty the index should be refreshed. Previously the cached index would cause describe to think that the index was dirty when, in reality, it was just stale.

请注意,您描述的确切步骤顺序不应该有此问题,因为 git status 更新了索引。但我仍然认为您遇到了同样的问题,因为您描述的解决方法匹配。以下是我如何演示该问题:

% git describe --tags --dirty
v1.0.0
% touch pom.xml
% git describe --tags --dirty
v1.0.0-dirty
% git status
# On branch dev
nothing to commit (working directory clean)
% git describe --tags --dirty
v1.0.0

此处运行“git status”作为副作用更新索引并修复“git describe”输出,就像您的解决方法一样。 git 1.7.6 及更早版本的正确管道修复是:

% touch pom.xml
% git describe --tags --dirty
v1.0.0-dirty
% git update-index --refresh
% git describe --tags --dirty
v1.0.0

关于git - 为什么 `git describe -dirty` 在描述干净 checkout 时添加 `-dirty` 后缀?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16035240/

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