git pull with “--work-tree” flag fails

北战南征 提交于 2019-12-08 05:33:59

问题


I'm running (in a script - trying to avoid using cd):

git --git-dir=/test/.git --work-tree=/test/ pull

And getting:

fatal: /usr/lib/git-core/git-pull cannot be used without a working tree.

Note that I've run other commands with exactly this structure that have worked (in particular, add, commit, and pull), so I think it's just a pull problem.

A similar problem is documented here: Git pull fails to parse syntax, but it's not quite the same - they get a different error (and they're running on Windows, so who knows... I'm on Ubuntu).


回答1:


Thanks to isbadawi for this answer.

Turns out this question has been answered before: git pull while not in a git directory.

In a nutshell, this is a bug with git pull. However, since pull is basically an alias for fetching and merging, the following is equivalent to pull (copied from the above link):

cd /X
git --git-dir=/X/Y/.git fetch
git --git-dir=/X/Y/.git --work-tree=/X/Y merge origin/master


来源:https://stackoverflow.com/questions/15080877/git-pull-with-work-tree-flag-fails

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