与 Libgit2 相比,Windows 上的 Git 存储速度非常慢

Abd*_*oui 5 c# git libgit2 libgit2sharp git-for-windows

最近我一直在使用 git stash 很多次,我一直在想它真的很慢,即使在一个只有一个文件的新存储库上也是如此。我读过这个问题,大约GIT中藏匿缓慢而这另一个而想尽回答这些问题,但没有任何实际工作。

例如,我已经完成了以下步骤来重现它:

  1. git init
  2. touch file.txt
  3. vim file.txt (编辑文件添加 2 行)
  4. git add .
  5. git commit -m "Initial commit"
  6. vim file.txt (再次编辑添加1行)
  7. 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
Run Code Online (Sandbox Code Playgroud)

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");
}
Run Code Online (Sandbox Code Playgroud)

此代码需要 74 毫秒来隐藏相同的更改。如果 Libgit2 这么快,那么应该可以加速git stash命令。我怎样才能做到这一点?

实际使用 windows 10 64bit 和 git 2.11 64bits。其他 git 命令(如状态、添加、提交等)工作正常。

更新:我已经更新到 git 2.13,现在是 14,53 秒git stash...

更新 2:我已更新到 git 2.15 并尝试相同的测试time git stash返回real 0m6,553s。还是真的慢...

Abd*_*oui 3

从 Git 2.22 开始

自 Git 2.22 以来,之前的实验性功能现已稳定并成为默认选项。

Git 2.22 以下

一年后,安装 Git 2.19 时,我在 git 安装过程中看到了一个复选框,用于启用新的实验性内置存储。

实验性内置 git stash

就我而言,它工作得很好,我注意到与旧的实现(使用脚本)相比,性能有了巨大的提高,而且它实际上与在 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
Run Code Online (Sandbox Code Playgroud)