与Libgit2相比,Git藏在窗户上的速度极慢
最近我一直在使用git stash多次,我一直认为它真的很慢,即使在一个带有单个文件的新存储库中也是如此。 我已经阅读了关于git stash slowness和另一个 问题的这个问题 ,并尝试了对这些问题的每个答案,但实际上没有任何效果。
例如,我已经完成了以下步骤来重现它:
git init
-
touch file.txt
-
vim file.txt
(编辑文件添加2行) -
git add .
-
git commit -m "Initial commit"
-
vim file.txt
(再次编辑添加1行) -
time git stash
输出:
$ time git stash Saved working directory and index state WIP on master: b9454ed Initial commit HEAD is now at b9454ed Initial commit real 0m8.042s user 0m0.000s sys 0m0.046s
用于存储单行的8秒钟是如此之多。 现在使用libgit2sharp进行测试:
static void Main(string[] args) { Repository repo=new Repository(@"C:\Users\UserTest\TestGitRepo"); repo.Stashes.Add(new Signature("test", "test@test.com", new DateTimeOffset(DateTime.Now)), "Stash on master"); }
此代码需要74毫秒来存储相同的更改。 如果Libgit2那么快,那么应该可以加速git stash
命令。 我怎样才能做到这一点?
实际上使用windows 10 64bit和git 2.11 64bits。 其他git命令(如status,add,commit等)工作正常。
更新:我已经更新到git 2.13,现在它是git stash
的14,53s …
更新2:我已经更新到git 2.15并尝试相同的测试time git stash
返回real 0m6,553s
。 还是很慢……
一年后,安装git 2.19我在git安装期间看到了一个复选框,以启用新的实验内置存储。
在我的情况下它工作正常,我注意到与旧的实现(使用脚本)相比,性能有了很大提高,而且它实际上和在linux中使用相同的命令一样快。
这里的结果完全按照相同的步骤:
$ time git stash Saved working directory and index state WIP on master: 7a29b92 Initial commit real 0m0,120s user 0m0,000s sys 0m0,015s
一旦这成为git stash的官方和稳定版本,我将更新。
要添加到现有答案,您可以启用新function(如果已安装2.19或更高版本):
git config --global stash.usebuiltin true
这也适用于便携版。
请注意,此function似乎不适用于子模块。 https://github.com/git-for-windows/git/issues/1820