Git Stash & Worktree Woes

。_饼干妹妹 提交于 2020-01-10 19:32:12

问题


I'm having a helluva time getting git to cooperate with my user-defined worktree that exists outside the folder that contains my .git directory.

Basically the setup is like this: I have two directories, one called "git-worktree" which houses the file I want to track & another called "git-dir" which contains the repository's .git folder aka the GIT_DIR.

I init the repository by cd'ing into folder "git-dir" and running:

git --git-dir=./.git --work-tree=/Users/braitsch/Test/git-worktree/ init

This successfully initializes the repository and while I'm in the "git-dir" folder I can add files that are in the work-tree, run git status and commit them. Cool.

The kick in the balls here comes when I try to run git stash which slaps me with the error:

fatal: /usr/local/git/libexec/git-core/git-stash cannot be used without a working tree.

Now this is BS because I know (or at least I think) I have the work-tree set to the "git-worktree" folder that contains the files I want to track.

git config --local -l shows me the following :

core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.worktree=/Users/braitsch/Test/git-worktree
core.ignorecase=true

I even tried manually adding the .git folder to the local config file to see if that helps but to no avail.

core.gitdir=/Users/braitsch/Test/git-dir/.git

Now here come's the kicker. Git stash will work if I set the worktree to a directory that is a parent of the git-dir e.g. If I set the worktree to say my home directory.

core.worktree=/Users/braitsch/

So the question I have for you guys is what setting am I missing to tell git to allow my worktree to exist anywhere on the filesystem, not just along a parent path of the git-dir back up to the root? Surely there must be a way to place your git-dir & your work-tree wherever you want and after telling git where they are have everything work? Thanks much for reading. Any insights would be graciously appreciated.


回答1:


git --git-dir=<your path> --work-tree=<work tree path> stash

should work. Have you tried absolute paths?

UPDATE:

seems to be a bug. The extended functionality of --git-dir option was only added recently and some commands like git stash don't have the new implementation yet.

git-stash is a bash script. You could hack it and remove the require working dir check then cd into the working folder.



来源:https://stackoverflow.com/questions/6392862/git-stash-worktree-woes

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