本文介绍了为什么`git describe -dirty`在描述干净结帐时添加`-dirty`后缀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我刚刚发现 code>然后 gitk 也显示本地未提交更改,未检入到索引,然后列出工作目录中的每个文件,但没有针对它们的差异,只需 ----文件名---- 行。 进一步更新:由于这仍然是一个问题,我最终编写了一个 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 1.7.7修复此问题的 git commit 描述了问题: 请注意,您描述的步骤的确切顺序不应该有这个问题,因为 git status 会更新索引。但我仍然认为你看到了同样的问题,因为你描述的解决方法匹配。以下是我展示该问题的方式: %git describe --tags --dirty v1.0.0 %touch pom.xml %git describe --tags --dirty v1.0.0-dirty %git status #在分支上开发没有任何东西提交(工作目录清理)%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 I have just discovered the --dirty option to git describe and it looks like it should do something very useful, i.e. append a suffix to the output of git describe when the working tree is dirty, however that doesn't seem to be the case on some of my repositories:$ git status# On branch 8.30nothing to commit (working directory clean)$ git describe --dirty8.30rel-8-g9c1cbdb-dirtyI thought this might be because the working directory is dirty relative to the tag, but that doesn't seem to be the case either:$ git status# On branch 1.4nothing to commit (working directory clean)$ git describe --tags --dirty --long1.4rel-0-gfedfe66-dirtyI used to make extensive use of hg id when I used to use Mercurial and liked the fact that it's default behaviour was to add a + suffix to any commit hash it reported for a dirty repository, so have been looking out for a git equivalent since, but git describe --dirty doesn't appear to do what I would expect given the documentation:Am I misunderstanding what --dirty should do, or am I not using it correctly?In case it makes any difference, all of the git repositories are deployed via buckminster so there are no submodules involved and the filesystem is an nfs share.Update: I have discovered a work around, but I have absolutely no idea how this could possibly be making a difference.If I run git diff --quiet HEAD on the repo then all of a sudden the git describe works as I expect:$ git status# On branch 8.30nothing to commit (working directory clean)$ git describe --dirty8.30rel-8-g9c1cbdb-dirty$ git diff --quiet HEAD$ git describe --dirty8.30rel-8-g9c1cbdbI also spotted that when git describe was reporting the repository as dirty then gitk also showed "Local uncommitted changes, not checked in to index" and then listed each file in the working directory, but with no diffs against them, just the ---- filename ---- lines.Further update: As this continued to be a problem, I eventually wrote a git-describe-dirty script, which starts by running git describe --dirty but if it finds the repository to be dirty, runs git update-index -q --refresh before trying again and taking the second result.When iterating through hundreds of repositories, using git describe-dirty and only running the index update for a repository which initially indicates it is dirty saves a great deal of time compared to running git update-index -q --refresh ; git describe --dirty every time. 解决方案 If you are running git 1.7.6 or earlier, you need to run git update-index --refresh before using git describe --dirty, because the index may be stale. Your workaround of using git diff --quiet HEAD works because "git diff" is a porcelain command, and probably updates the index itself.The git commit that fixes this for git 1.7.7 describes the problem:Note that the exact sequence of steps you describe shouldn't have this problem, because git status updates the index. But I still think you are seeing this same issue because the workaround you describe matches. Here is how I demonstrate the issue:% git describe --tags --dirtyv1.0.0% touch pom.xml% git describe --tags --dirtyv1.0.0-dirty% git status# On branch devnothing to commit (working directory clean)% git describe --tags --dirtyv1.0.0Here running "git status" updates the index as a side effect and fixes "git describe" output, just as with your workaround. The proper plumbing fix for git 1.7.6 and earlier would be:% touch pom.xml% git describe --tags --dirtyv1.0.0-dirty% git update-index --refresh% git describe --tags --dirtyv1.0.0 这篇关于为什么`git describe -dirty`在描述干净结帐时添加`-dirty`后缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-04 21:01