Git - 推送失败/此操作必须在工作树中 运行

Git - push failure / This operation must be run in a work tree

我正在按照 Git 专业书籍 (http://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server) 在 Ubuntu 上设置我的第一个 git 远程服务器。 在我遵循这个之后:

$ git remote add origin git@gitserver:/opt/git/inventory.git
$ git push origin Windows

我收到这条消息:

Counting objects: 33, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (28,28) done.
Writing objects: 100% (33/33), 7.30 KiB | 0 bytes/s, done.
Total 33 (delta 13), reused 0 (delta 0)
To git@gitserver:/opt/git/inventory.git
 * [new branch]    Windows -> Windows

但是当我在远程服务器(在 /opt/git/inventory.git/ 中)键入 git status 时,我收到错误消息 fatal: This operation must be run in a work tree

远程存储库似乎不包含本地存储库中的任何文件,当我将远程存储库克隆到不同的本地文件夹时,没有文件,只有 .git 文件夹。

我在这里查看了其他相关问题:

fatal: This operation must be run in a work tree

Why am I getting the message, "fatal: This operation must be run in a work tree?"

Getting “fatal: This operation must be run in a work tree?” on bare repository

但我不清楚为什么会发生这种情况以及我能做些什么来补救它。

有问题的远程存储库是 bare repository

它将只包含 git 内部存储的打包对象和引用等,不会检出任何常规代码文件。因此,将没有工作树,因此没有工作 git status.

就是说,要检查您的更改是否已推送,只需将有问题的存储库克隆到另一个位置,您就会发现您的文件没问题:

git clone /opt/git/inventory.git some/location/inventory_clone

您可能需要在新克隆的存储库中执行 git checkout master 才能真正看到代码文件。