git stash is slow on windows

安稳与你 提交于 2019-11-28 04:28:27

With Git for Windows 2.19 (Sept. 2018), git stash (and git rebase) are no longer script-only, but actually a binary compiled with git.exe.
See git-for-windows/build-extra PR 203.

To activate them, type:

git config --global rebase.useBuiltin true
git config --global stash.useBuiltin true

Warning:

As nice as the speed-ups are, the patches in question are still in flux, and they are not battle-tested at all.

So, for now, the script version of git stash remains the default, that way:

  • users who want the raw speed improvement we got through three Google Summer of Code projects working in parallel can have that,
  • while others who are reluctant to play guinea pig by running only well-tested code can stay on the safe side.

The point remains: in the next versions of Git, the bash script for git-stash will eventually disappear, and its replacement is and will be faster.


Update Q2 2019, with Git 2.22, git stash is entirely rewritten in C.

See commit 40af146, commit 48ee24a, commit ef0f0b4, commit 64fe9c2, commit 1ac528c, commit d553f53, commit d4788af, commit 41e0dd5, commit dc7bd38, commit 130f269, commit bef55dc, commit dac566c, commit ab8ad46 (25 Feb 2019) by Paul-Sebastian Ungureanu (weekly-digest[bot]).
See commit c4de61d, commit 577c199, commit 4e2dd39, commit 8a0fc8d (25 Feb 2019) by Joel Teichroeb (klusark).
See commit 7906af0, commit 90a4627, commit 8d8e9c2 (25 Feb 2019) by Johannes Schindelin (dscho).
(Merged by Junio C Hamano -- gitster -- in commit e36adf7, 22 Apr 2019)

You can still use the shell script with git legacy-stash.

And:

stash: convert stash--helper.c into stash.c

The old shell script git-stash.sh was removed and replaced entirely by builtin/stash.c.
In order to do that, create and push were adapted to work without stash.sh.

For example, before this commit, git stash create called git stash--helper create --message "$*". If it called git stash--helper create "$@", then some of these changes wouldn't have been necessary.

This commit also removes the word helper since now stash is called directly and not by a shell script.

There are optimizations:

stash: optimize get_untracked_files() and check_changes()

This commits introduces a optimization by avoiding calling the same functions again.
For example, git stash push -u would call at some points the following functions:

  • check_changes() (inside do_push_stash())
  • do_create_stash(), which calls: check_changes() and get_untracked_files()

Note that check_changes() also calls get_untracked_files().
So, check_changes() is called 2 times and get_untracked_files() 3 times.

The old function check_changes() now consists of two functions: get_untracked_files() and check_changes_tracked_files().

These are the call chains for push and create:

  • push_stash() -> do_push_stash() -> do_create_stash()
  • create_stash() -> do_create_stash()

To prevent calling the same functions over and over again, check_changes() inside do_create_stash() is now placed in the caller functions (create_stash() and do_push_stash()).
This way check_changes() and get_untracked files() are called only one time.

git-stash is a script, not a command compiled in the git.exe binary.

On linux : I can find git-stash at /usr/lib/git-core/git-stash - I will let you look for the correct path on windows ...


This script uses #!/bin/sh to run, I don't know what shell implementation is used when you run this on windows.

You can try to run it with another compatible shell (here: bash) :

# the git-core/ dir needs to be in the PATH,
# obviously  you will need to provide the correct path for your git-core dir

$ PATH=/usr/lib/git-core:$PATH bash /usr/lib/git-core/git-stash

You can also turn the -x flag, which will print a trace of all commands executed, and visually check if one of the sub commands seems to be the hanger :

$ PATH=/usr/lib/git-core:$PATH bash -x /usr/lib/git-core/git-stash
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!