Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git stash on windows extremly slow compared to Libgit2

Tags:

Recently I've been using git stash many times and I've been thinking that it is really slow, even on a new repository with a single file. I've read this question about git stash slowness and this other one and tried every answer to these questions but nothing actually works.

For example I've done the following steps to reproduce it:

  1. git init
  2. touch file.txt
  3. vim file.txt (edit the file adding 2 lines)
  4. git add .
  5. git commit -m "Initial commit"
  6. vim file.txt (edit it again adding 1 line)
  7. time git stash

Output:

$ 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 seconds for stashing a single line is so much time. Now a test using libgit2sharp:

static void Main(string[] args)
{
    Repository repo=new Repository(@"C:\Users\UserTest\TestGitRepo");

    repo.Stashes.Add(new Signature("test", "[email protected]", new DateTimeOffset(DateTime.Now)), "Stash on master");
}

This code takes 74ms to stash the same change. If Libgit2 is that fast then it should be possible to speed up git stash command. How can I achieve this?

Actually using windows 10 64bit and git 2.11 64bits. Other git commands (like status, add, commit, etc.) work fine.

UPDATE: I've updated to git 2.13 and now it's 14,53s for git stash...

UPDATE 2: I've updated to git 2.15 and trying the same test time git stash returns real 0m6,553s. Still really slow...

like image 486
Abdelilah El Aissaoui Avatar asked May 24 '17 13:05

Abdelilah El Aissaoui


People also ask

Is git stash stack or queue?

Every documentation, article and book (except Git Internals) says that the git stash is a stack.

Does git Clean affect stash?

A safer option is to run git stash --all to remove everything but save it in a stash. Assuming you do want to remove cruft files or clean your working directory, you can do so with git clean .

What is the difference between stash and git?

The git commit and git stash commands are similar in that both take a snapshot of modified files in the git working tree and store that snapshot for future reference. The key differences between the two are as follows: A commit is part of the public git history; a stash is stored locally.

Does git stash depend on branch?

No and No. git stash is per-repository.


2 Answers

Since Git 2.22

Since Git 2.22 the previously experimental feature is now stable and the default option.

Below Git 2.22

One year later, installing Git 2.19 I've seen a checkbox during git installation to enable the new experimental built-in stash.

Experimental built-in git stash

In my case it works fine and I've noticed a huge performance improvement compared to the old implementation (which was using a script) and it's actually as fast as using the same command in linux.

Here the results following exactly the same steps:

$ time git stash
Saved working directory and index state WIP on master: 7a29b92 Initial commit

real    0m0,120s
user    0m0,000s
sys     0m0,015s
like image 67
Abdelilah El Aissaoui Avatar answered Sep 21 '22 10:09

Abdelilah El Aissaoui


To add to the existing answer you can enable the new feature if you’ve already installed 2.19 or later with:

git config --global stash.usebuiltin true

This works with the portable edition as well.

Please note that this feature doesn’t seem to work with submodules yet. https://github.com/git-for-windows/git/issues/1820

like image 34
asaddev Avatar answered Sep 21 '22 10:09

asaddev