剩余index.lock文件
git status剩余index.lock文件时,从病理上讲会很慢。
发生这种情况尤其是在您git submodules有时,因为那样的话,您通常不会注意到这样的剩余文件。
摘要:运行find .git/ -name index.lock,然后在检查剩余文件是否确实未被当前正在运行的程序使用后,将其删除。
细节
我发现回购中的shell git状态非常慢,在Ubuntu 16.04上使用git 2.19。
深入研究,发现/usr/bin/time git status在我的assetsgit子模块中花费了1.7秒。
找到strace那个git用读取我所有的大文件mmap。通常不这样做,通常stat就足够了。
我搜索了这个问题,发现使用索引和Racy Git问题。
尝试过git update-index somefile(在我的情况下gitignore在子模块结帐中),
但失败了
fatal: Unable to create '/home/niklas/src/myproject/.git/modules/assets/index.lock': File exists.
Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.
这是一个经典的错误。通常您在任何git操作中都会注意到它,但是对于您不经常提交的子模块,您可能几个月都不会注意到它,因为它仅在向索引添加内容时出现;该警告不会在只读上引发git status。
删除index.lock文件后,git status立即变得很快,然后mmaps消失了,现在快了1000倍。
因此,如果您的git状态异常缓慢,请检查find .git/ -name index.lock并删除剩余的。