Git状态需要很长时间才能完成

时间:2022-10-19 18:56:16

I'm using git to manage files in a local directory on a Windows machine - no network is involved here, I'm not pushing or pulling to/from another machine. My directory has maybe 100 files in it, all test files, pretty small. When I run git status, it regularly takes 20-30 seconds to complete. Is this normal? Is there anything I can do to speed it up, or a better way to see what the state of my repository is (changed files, untracked files, etc)? Other git commands seem to complete much faster.

我正在使用git来管理Windows机器上本地目录中的文件 - 这里没有涉及网络,我没有推送或拉出另一台机器。我的目录中可能包含100个文件,所有测试文件都非常小。当我运行git status时,它通常需要20-30秒才能完成。这是正常的吗?有什么我可以做的加快速度,或者更好的方式来查看我的存储库的状态(更改的文件,未跟踪的文件等)?其他git命令似乎完成得更快。

11 个解决方案

#1


Have you tried git gc? This cleans cruft out of the git repo.

你试过git gc吗?这清除了git repo中的残余。

#2


Are you using some kind of virus protection software? Maybe that is interfering with things. git is very fast for me on windows with repositories of 1000's of files.

您使用的是某种病毒防护软件吗?也许这会干扰事情。对于我来说,git对我来说非常快,有1000个文件的存储库。

#3


On a similar issue I found that having a git repo in a directory below my existing git repo caused a massive slow down.

在一个类似的问题上,我发现在我现有的git repo下面的目录中有一个git repo会导致大幅减速。

I moved the secondary git repo somewhere else and now the speed is fast!

我把辅助git repo移到了其他地方,现在速度很快!

#4


Have you tried repacking? git-repack.

你尝试过重新包装吗?混帐重新包装。

Otherwise, try duplicating the directory, and deleting the .git folder in the duplicated directory. Then create a new git directory and see if it's still slow.

否则,请尝试复制目录,并删除重复目录中的.git文件夹。然后创建一个新的git目录,看看它是否仍然很慢。

If it's still slow, then it sounds like a system or hardware issue. Git finishes status on hundreds of files for me in less than 5 seconds.

如果它仍然很慢,那么它听起来像是一个系统或硬件问题。 Git在不到5秒的时间内完成了数百个文件的状态。

#5


For some reason git status is particularly slow after moving or copying the repository folder to a new location.

由于某种原因,将存储库文件夹移动或复制到新位置后,git状态特别慢。

Subsequent runs are usually quicker in this case.

在这种情况下,后续运行通常更快。

#6


The issue for me was that I had a lot of different repositories cloned onto my local hard drive, the more repos you have the longer it will take to run commands like git status.

对我来说问题是我有很多不同的存储库克隆到我的本地硬盘驱动器上,你有更多的存储库运行命令,如git status。

I simply deleted a lot of the repos which I no longer needed locally, and my git status went from 1minute~ to 5 seconds.

我只是删除了很多本地不再需要的回购,我的git状态从1分钟到5秒。

I can't see any answers similar to this here.

我在这里看不到任何类似的答案。

#7


Another aspect of git status which will be improved (in Git 2.14.x/2.15, Q4 2017) is when it shows ignored files as well (git status --ignored)

git状态的另一个方面将得到改进(在Git 2.14.x / 2.15,2017年第4季度),它同时显示被忽略的文件(git status --ignored)

"git status --ignored", when noticing that a directory without any tracked path is ignored, still enumerated all the ignored paths in the directory, which is unnecessary.
The codepath has been optimized to avoid this overhead.

“git status --ignored”,当注意到没有任何跟踪路径的目录被忽略时,仍然枚举目录中所有被忽略的路径,这是不必要的。已对代码路径进行了优化以避免此开销。

See commit 5aaa7fd (18 Sep 2017) by Jameson Miller (jamill).
(Merged by Junio C Hamano -- gitster -- in commit 075bc9c, 29 Sep 2017)

请参阅Jameson Miller(jamill)提交的5aaa7fd(2017年9月18日)。 (由Junio C Hamano合并 - gitster - 在提交075bc9c,2017年9月29日)

Improve performance of git status --ignored

Improve the performance of the directory listing logic when it wants to list non-empty ignored directories. In order to show non-empty ignored directories, the existing logic will recursively iterate through all contents of an ignored directory.
This change introduces the optimization to stop iterating through the contents once it finds the first file. This can have a significant improvement in 'git status --ignored' performance in repositories with a large number of files in ignored directories.

当想要列出非空的忽略目录时,提高目录列表逻辑的性能。为了显示非空的忽略目录,现有逻辑将递归迭代忽略目录的所有内容。此更改引入优化,以便在找到第一个文件后停止迭代内容。这可以显着提高存储库中的“git status --ignored”性能,并在忽略的目录中包含大量文件。

For an example of the performance difference on an example repository with 196,000 files in 400 ignored directories:

有关400个忽略目录中196,000个文件的示例存储库的性能差异示例:

| Command                    |  Time (s) |
| -------------------------- | --------- |
| git status                 |   1.2     |
| git status --ignored (old) |   3.9     |
| git status --ignored (new) |   1.4     |

For more improvment (set in Git 2.17, Q2 2018), see this answer.

有关更多改进(在Git 2.17,2018年第二季度中设置),请参阅此答案。

#8


Running git fsck has resolved this issue for me in the past.

运行git fsck过去已经为我解决了这个问题。

#9


In my case, slowness was caused by running git status as a different user from the owner of the files in the project.

在我的情况下,缓慢是由于将git status作为与项目中文件所有者的不同用户运行而引起的。

While not applicable in all instance, a simple chown to your current user may do the trick.

虽然并不适用于所有情况,但对当前用户的简单颂歌可能会起到作用。

#10


My git status was very slow (up to one minute), because the global .gitignore file was located in my windows userprofile, which was stored on an inaccessible network share.

我的git状态非常慢(最多一分钟),因为全局.gitignore文件位于我的windows userprofile中,该文件存储在无法访问的网络共享中。

git config --global core.excludesfile
showed something like \\Nxxxx0\User\Username\Eigene Dateien\gitignore_global.txt

git config --global core.excludesfile显示类似\\ Nxxxx0 \ User \ Username \ Eigene Dateien \ gitignore_global.txt

For some reason \\Nxxxx0 was inaccessible and my userprofile was loaded from a backup system \\Nxxxxx1. It took some time to figure that out, because usually my userprofile is bound to a drive letter by an enterprise startup script and accessing that drive letter was working as usual. I'm not sure why the git-config used the network share and not the drive letter (probably a younger me is to blame)

出于某种原因\\ Nxxxx0无法访问,我的userprofile是从备份系统\\ Nxxxxx1加载的。花了一些时间来解决这个问题,因为通常我的userprofile被企业启动脚本绑定到驱动器号,访问该驱动器号就像往常一样工作。我不确定为什么git-config使用了网络共享而不是驱动器号(可能是一个年轻的我应该受到责备)

After setting
git config --global core.excludesfile $HOME/Eigene\ Dateien/gitignore_global.txt
git status was back to normal speed.

设置git config后--global core.excludesfile $ HOME / Eigene \ Dateien / gitignore_global.txt git status恢复正常速度。

#11


Try starting with a fresh clone of your checkout.

尝试从结帐的新克隆开始。

git clone myrepo mynewrepo

and then do git status in mynewrepo.

然后在mynewrepo中执行git状态。

Alternatively, and if you are braver, clean out the rubbish from your existing checkout.

或者,如果你更勇敢,清理现有结账的垃圾。

git clean -dfx

This avoids git having to scan some (possibly large) set of ignored or not checked-in files.

这避免了git必须扫描一些(可能很大的)被忽略或未签入的文件集。

#1


Have you tried git gc? This cleans cruft out of the git repo.

你试过git gc吗?这清除了git repo中的残余。

#2


Are you using some kind of virus protection software? Maybe that is interfering with things. git is very fast for me on windows with repositories of 1000's of files.

您使用的是某种病毒防护软件吗?也许这会干扰事情。对于我来说,git对我来说非常快,有1000个文件的存储库。

#3


On a similar issue I found that having a git repo in a directory below my existing git repo caused a massive slow down.

在一个类似的问题上,我发现在我现有的git repo下面的目录中有一个git repo会导致大幅减速。

I moved the secondary git repo somewhere else and now the speed is fast!

我把辅助git repo移到了其他地方,现在速度很快!

#4


Have you tried repacking? git-repack.

你尝试过重新包装吗?混帐重新包装。

Otherwise, try duplicating the directory, and deleting the .git folder in the duplicated directory. Then create a new git directory and see if it's still slow.

否则,请尝试复制目录,并删除重复目录中的.git文件夹。然后创建一个新的git目录,看看它是否仍然很慢。

If it's still slow, then it sounds like a system or hardware issue. Git finishes status on hundreds of files for me in less than 5 seconds.

如果它仍然很慢,那么它听起来像是一个系统或硬件问题。 Git在不到5秒的时间内完成了数百个文件的状态。

#5


For some reason git status is particularly slow after moving or copying the repository folder to a new location.

由于某种原因,将存储库文件夹移动或复制到新位置后,git状态特别慢。

Subsequent runs are usually quicker in this case.

在这种情况下,后续运行通常更快。

#6


The issue for me was that I had a lot of different repositories cloned onto my local hard drive, the more repos you have the longer it will take to run commands like git status.

对我来说问题是我有很多不同的存储库克隆到我的本地硬盘驱动器上,你有更多的存储库运行命令,如git status。

I simply deleted a lot of the repos which I no longer needed locally, and my git status went from 1minute~ to 5 seconds.

我只是删除了很多本地不再需要的回购,我的git状态从1分钟到5秒。

I can't see any answers similar to this here.

我在这里看不到任何类似的答案。

#7


Another aspect of git status which will be improved (in Git 2.14.x/2.15, Q4 2017) is when it shows ignored files as well (git status --ignored)

git状态的另一个方面将得到改进(在Git 2.14.x / 2.15,2017年第4季度),它同时显示被忽略的文件(git status --ignored)

"git status --ignored", when noticing that a directory without any tracked path is ignored, still enumerated all the ignored paths in the directory, which is unnecessary.
The codepath has been optimized to avoid this overhead.

“git status --ignored”,当注意到没有任何跟踪路径的目录被忽略时,仍然枚举目录中所有被忽略的路径,这是不必要的。已对代码路径进行了优化以避免此开销。

See commit 5aaa7fd (18 Sep 2017) by Jameson Miller (jamill).
(Merged by Junio C Hamano -- gitster -- in commit 075bc9c, 29 Sep 2017)

请参阅Jameson Miller(jamill)提交的5aaa7fd(2017年9月18日)。 (由Junio C Hamano合并 - gitster - 在提交075bc9c,2017年9月29日)

Improve performance of git status --ignored

Improve the performance of the directory listing logic when it wants to list non-empty ignored directories. In order to show non-empty ignored directories, the existing logic will recursively iterate through all contents of an ignored directory.
This change introduces the optimization to stop iterating through the contents once it finds the first file. This can have a significant improvement in 'git status --ignored' performance in repositories with a large number of files in ignored directories.

当想要列出非空的忽略目录时,提高目录列表逻辑的性能。为了显示非空的忽略目录,现有逻辑将递归迭代忽略目录的所有内容。此更改引入优化,以便在找到第一个文件后停止迭代内容。这可以显着提高存储库中的“git status --ignored”性能,并在忽略的目录中包含大量文件。

For an example of the performance difference on an example repository with 196,000 files in 400 ignored directories:

有关400个忽略目录中196,000个文件的示例存储库的性能差异示例:

| Command                    |  Time (s) |
| -------------------------- | --------- |
| git status                 |   1.2     |
| git status --ignored (old) |   3.9     |
| git status --ignored (new) |   1.4     |

For more improvment (set in Git 2.17, Q2 2018), see this answer.

有关更多改进(在Git 2.17,2018年第二季度中设置),请参阅此答案。

#8


Running git fsck has resolved this issue for me in the past.

运行git fsck过去已经为我解决了这个问题。

#9


In my case, slowness was caused by running git status as a different user from the owner of the files in the project.

在我的情况下,缓慢是由于将git status作为与项目中文件所有者的不同用户运行而引起的。

While not applicable in all instance, a simple chown to your current user may do the trick.

虽然并不适用于所有情况,但对当前用户的简单颂歌可能会起到作用。

#10


My git status was very slow (up to one minute), because the global .gitignore file was located in my windows userprofile, which was stored on an inaccessible network share.

我的git状态非常慢(最多一分钟),因为全局.gitignore文件位于我的windows userprofile中,该文件存储在无法访问的网络共享中。

git config --global core.excludesfile
showed something like \\Nxxxx0\User\Username\Eigene Dateien\gitignore_global.txt

git config --global core.excludesfile显示类似\\ Nxxxx0 \ User \ Username \ Eigene Dateien \ gitignore_global.txt

For some reason \\Nxxxx0 was inaccessible and my userprofile was loaded from a backup system \\Nxxxxx1. It took some time to figure that out, because usually my userprofile is bound to a drive letter by an enterprise startup script and accessing that drive letter was working as usual. I'm not sure why the git-config used the network share and not the drive letter (probably a younger me is to blame)

出于某种原因\\ Nxxxx0无法访问,我的userprofile是从备份系统\\ Nxxxxx1加载的。花了一些时间来解决这个问题,因为通常我的userprofile被企业启动脚本绑定到驱动器号,访问该驱动器号就像往常一样工作。我不确定为什么git-config使用了网络共享而不是驱动器号(可能是一个年轻的我应该受到责备)

After setting
git config --global core.excludesfile $HOME/Eigene\ Dateien/gitignore_global.txt
git status was back to normal speed.

设置git config后--global core.excludesfile $ HOME / Eigene \ Dateien / gitignore_global.txt git status恢复正常速度。

#11


Try starting with a fresh clone of your checkout.

尝试从结帐的新克隆开始。

git clone myrepo mynewrepo

and then do git status in mynewrepo.

然后在mynewrepo中执行git状态。

Alternatively, and if you are braver, clean out the rubbish from your existing checkout.

或者,如果你更勇敢,清理现有结账的垃圾。

git clean -dfx

This avoids git having to scan some (possibly large) set of ignored or not checked-in files.

这避免了git必须扫描一些(可能很大的)被忽略或未签入的文件集。