没有工作树就不能使用 git-pull
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21605884/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git-pull cannot be used without a working tree
提问by RoyTheBoy
I'm trying to pull from a remote repo I've just set up and I'm getting the message git-pull cannot be used without a working tree
我正在尝试从我刚刚设置的远程仓库中拉取数据,但收到消息 git-pull 不能在没有工作树的情况下使用
Everything I've read seems to point at my .git directory but it seems fine
我读过的所有内容似乎都指向我的 .git 目录,但似乎很好
git branch
gives the output
给出输出
* master
and
和
git ls-tree --full-tree -r HEAD
list loads of entries like this
列出大量这样的条目
100644 blob c825c0607f77e1df4e05920037a2ce09c08e5180app/assets/javascripts/ready.js
which looks correct and makes me think I have managed to push the files correctly to this repo ?
这看起来正确,让我觉得我已经设法将文件正确地推送到这个 repo ?
git status
give the output
给出输出
fatal: This operation must be run in a work tree
and ls -l .git gives
和 ls -l .git 给出
drwxrwxr-x 2 roy roy 4096 Feb 6 14:24 branches
-rw-rw-r-- 1 roy roy 66 Feb 6 14:24 config
-rw-rw-r-- 1 roy roy 73 Feb 6 14:24 description
-rw-rw-r-- 1 roy roy 23 Feb 6 14:24 HEAD
drwxrwxr-x 2 roy roy 4096 Feb 6 14:24 hooks
drwxrwxr-x 2 roy roy 4096 Feb 6 14:24 info
drwxrwxr-x 4 roy roy 4096 Feb 6 14:24 objects
drwxrwxr-x 4 roy roy 4096 Feb 6 14:24 refs
which does seem a bit odd, as it looks just like it did before the push.
这确实有点奇怪,因为它看起来就像在推送之前一样。
can anyone help me with what I'm doing wrong? Is there something I have to do before I can do a git pull ? am I confused by that ls-tree command and the files haven't been pushed?
谁能帮我解决我做错了什么?在执行 git pull 之前,我需要做些什么吗?我是否对 ls-tree 命令感到困惑并且文件没有被推送?
回答by Arialdo Martini
It seems you are working in a bare repository.
看来您正在一个裸存储库中工作。
A bare repository is just like an ordinary one, except it has no working directory associated.
Being pull
a fetch
plus a merge
, it cannot be applied to bare repositories.
裸存储库就像普通存储库一样,只是它没有关联的工作目录。作为pull
一个fetch
加号merge
,它不能应用于裸存储库。
In details:
详细说明:
A git repository, after all, is just a .git
directory with a defined set of metadata stored in special directories (like refs
, where local and remote branches are stored, and objects
, which contains all the file contents, and so on).
毕竟,git 存储库只是一个.git
目录,其中包含存储在特殊目录中的一组定义的元数据(例如refs
,存储本地和远程分支的位置,以及objects
包含所有文件内容的 ,等等)。
Usually, a git repository is associated with a so called Working directory, which is the checkout of a certain commit: the developer can use the Working directory to perform modifications to the source code, and hence prepare the next commit.
通常,一个 git 存储库与一个所谓的工作目录相关联,它是某个提交的检出:开发人员可以使用工作目录对源代码进行修改,从而准备下一次提交。
Yet, sometimes, there's no need to have a Working directory. The most common case is when a repository is hosted in a shared server and it is used as the central, shared place used by developers to integrate their code. The repository must store all the information (hence, it has its own copy of the .git
directory), and developers can push their contribution to it, but no developers are meant to directly work on it; so, no Working directory is provided. This is a bare repository.
然而,有时,没有必要有一个工作目录。最常见的情况是,当存储库托管在共享服务器中时,它被用作开发人员用来集成其代码的中央共享位置。存储库必须存储所有信息(因此,它有自己的.git
目录副本),开发人员可以将他们的贡献推送给它,但没有开发人员可以直接处理它;所以,没有提供工作目录。这是一个裸存储库。
Now, there are some git commands that operate on the Working directory. These commands are not working on a bare repository, since it lacks a Working directory.
现在,有一些 git 命令在工作目录上运行。这些命令不适用于裸存储库,因为它缺少工作目录。
git pull
is one of them. git pull
is the combination of git fetch
and git merge
. Now, git fetch
involves only the .git
directory, so it can be performed on a bare repository. On the other side, git merge
requires a merge on the Working Directory to be performed. And since the working directory is not present, the command will fail.
git pull
是其中之一。git pull
是的组合git fetch
和git merge
。现在,git fetch
只涉及.git
目录,因此可以在裸存储库上执行。另一方面,git merge
需要在工作目录上执行合并。由于工作目录不存在,命令将失败。
pull
and merge
are not the only commands that cannot be performed on a bare repository. I strongly suggest you yo have a look to this interactive mapwhich will help you to select which operations cannot be performed on a bare repository (see the amazing Interactive Git Cheatsheet)
pull
并且merge
不是无法在裸存储库上执行的唯一命令。我强烈建议你看看这个交互式地图,它会帮助你选择哪些操作不能在裸存储库上执行(请参阅令人惊叹的交互式 Git 备忘单)