监视为什么 git add 。减缓?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31904167/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:15:25  来源:igfitidea点击:

To monitor why git add . slow?

git

提问by Léo Léopold Hertz ??

Assume project where no add and commit has been done for a long time. I do git add .but it takes too much time. I would like to estimate which files/directories are most expensive in the current case. I have a good .gitignorefile which works sufficiently but, still sometimes, I have too much and/or something too difficult to be added and committed to Git.

假设一个长期没有添加和提交的项目。我会,git add .但需要太多时间。我想估计在当前情况下哪些文件/目录最昂贵。我有一个很好的.gitignore文件,它可以正常工作,但有时,我有太多和/或太难添加和提交给 Git 的内容。

I have often directories which size is from 300GB to 2 TB in my directories. Although excluding them by directory/*and directory/in .gitignore, the addition is slow.

我的目录中经常有大小从 300GB 到 2 TB 的目录。尽管通过directory/*directory/in排除了它们.gitignore,但添加速度很慢。

How can you estimate which directories/files are too expensive to be committed?

您如何估计哪些目录/文件太昂贵而无法提交?

回答by Aaron Brager

Git slowness is generally from large binary files. This isn't because they're binary, just because binary files tend to be large and more complex to compress & diff.

Git 缓慢通常来自大型二进制文件。这不是因为它们是二进制文件,只是因为二进制文件往往很大,而且压缩和比较起来更复杂。

Based on your edit indicating the file sizes, I suspect this is your problem.

根据您对文件大小的编辑,我怀疑这是您的问题。

The answers to this questionoffer a few solutions: removing them from source control, manually running git gc, etc.

这个问题的答案提供了一些解决方案:将它们从源代码管理中删除,手动运行git gc等。

回答by VonC

"git add" needs to internally run "diff-files" equivalent,

" git add" 需要在内部运行 " diff-files" 等效,

With Git 2.20 (Q4 2018), the codepath learned the same optimization as "diff-files" has to run lstat(2)in parallel to find which paths have been updated in the working tree.

在 Git 2.20(2018 年第 4 季度)中,代码路径学习了与“ diff-files”相同的优化,必须lstat(2)并行运行以查找工作树中哪些路径已更新。

See commit d1664e7(02 Nov 2018) by Ben Peart (benpeart).
(Merged by Junio C Hamano -- gitster--in commit 9235a6c, 13 Nov 2018)

请参阅Ben Peart ( )提交的 d1664e7(2018 年 11 月 2 日)(由Junio C Hamano合并-- --提交 9235a6c 中,2018 年 11 月 13 日)benpeart
gitster

add: speed up cmd_add()by utilizing read_cache_preload()

During an "add", a call is made to run_diff_files()which calls check_removed()for each index-entry.
The preload_index()code distributes some of the costs across multiple threads.

Because the files checked are restricted to pathspec, adding individual files makes no measurable impact but on a Windows repo with ~200K files, 'git add .' drops from 6.3 seconds to 3.3 seconds for a 47% savings.

add: 加速cmd_add()利用read_cache_preload()

在“ add”期间run_diff_files(),会调用check_removed()每个索引条目。
preload_index()代码在多个线程之间分配一些成本。

由于检查的文件仅限于路径规范,因此添加单个文件不会产生可衡量的影响,但在具有约 200K 文件的 Windows 存储库中,“ git add .”从 6.3 秒下降到 3.3 秒,节省了 47%