git-stash unable to find work tree

我的未来我决定 提交于 2019-12-04 06:21:50

This is either a bug in the command’s behavior or its error reporting. The commands which require a work tree and are implemented as scripts1 verify its presence with this command:

git rev-parse --is-inside-work-tree

which will fail if you are not actually inside the work tree, contrary to what the error message implies. The commands which are implemented in C, on the other hand, call setup_work_tree, which automatically chdirs into the work tree. Whether the require_work_tree function in git-sh-setup could safely be altered to match this I do not know.

1. git-am.sh git-bisect.sh git-mergetool.sh git-pull.sh git-rebase--interactive.sh git-rebase.sh git-stash.sh git-submodule.sh

Edit:

Try setting the GIT_WORK_TREE environment variable to point to suitable folder.


Original answer:

That was a bit odd command. Try this instead. It's much easier:

mkdir yourRepo
cd yourRepo
git init
.. edit some files
git add .
git commit -m "First commit"

I ran into this using git for Windows 1.8.3 through ConEmu.

My problem seemed to be related to a drive mapping I had which mapped a path on the C: drive to P:\

git recognized the path for the mapped drive as /p at the prompt, but the setting for git config --local core.worktree was returning P:/

I reset it using git config --local core.worktree /p, which gave me p:/ as the new value, but that fixed stash. Seems like it didn't like the capital drive letter.

Turns out I simply had to cd /c and then cd /p to have git notice I had entered the working tree directory. Not sure why git is sensitive to cd but could not detect I was in the proper place when the shell was initialized.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!