我刚刚发现了一个--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
Run Code Online (Sandbox Code Playgroud)
我认为这可能是因为工作目录相对于标记是脏的,但似乎也不是这种情况:
$ git status
# On branch 1.4
nothing to commit (working directory clean)
$ git describe --tags --dirty --long
1.4rel-0-gfedfe66-dirty
Run Code Online (Sandbox Code Playgroud)
我过去hg id常常使用Mercurial并且喜欢它的默认行为是为+它为脏存储库报告的任何提交哈希添加后缀这一事实,所以一直在寻找git等价物,但是git describe --dirty没有在给出文档时,似乎做了我期望的事情:
Run Code Online (Sandbox Code Playgroud)--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在回购物上运行,那么突然之间的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
Run Code Online (Sandbox Code Playgroud)
我还发现,当git describe在报告存储库中dirty,然后gitk还显示"本地未提交的修改,在不检查索引",然后列在工作的每一个文件,但对他们没有任何的diff,只是---- 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 update-index --refresh在使用之前运行git describe --dirty,因为索引可能是陈旧的.你的使用git diff --quiet HEAD工作方法有效,因为"git diff"是一个瓷器命令,可能会更新索引本身.
运行git describe --dirty时,应刷新索引.以前,缓存的索引会导致describe认为索引是脏的,实际上它只是陈旧的.
请注意,您描述的确切步骤顺序不应该出现此问题,因为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
Run Code Online (Sandbox Code Playgroud)
这里运行"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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7071 次 |
| 最近记录: |