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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28412038/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:45:33  来源:igfitidea点击:

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

git

提问by bordeltabernacle

I'm following the Git Pro book ( http://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server) to set up my first git remote server on Ubuntu. After I follow this:

我正在按照 Git Pro 书(http://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server)设置我的第一个 git 远程服务器乌班图。在我按照这个之后:

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

I receive this message:

我收到这条消息:

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

But when I type git statuson the remote server (in /opt/git/inventory.git/) I get the error message fatal: This operation must be run in a work tree

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

The remote repository appears to not contain any of the files from the local repository and when I clone the remote repository into a different local folder there are no files, just the .git folder.

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

I have looked at other related questions on here:

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

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

变得“致命:这个操作必须在工作树中运行?” 在裸仓库上

but am no clearer as to why this is happening and what i can do to remedy it.

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

回答by u1860929

The remote repository in question is a bare repository.

有问题的远程存储库是一个裸存储库

It will only contain the packed objects and refs etc that git internally stores and won't have any of the regular code files checked out. As such, there will be no working tree, and hence no working git status.

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

That said, to check if your changes were pushed, just clone that repo in question to another location, and you will find your files all right:

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

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

You might need to do a git checkout masterin the newly cloned repo to actually see the code files.

您可能需要git checkout master在新克隆的 repo 中执行 a才能实际查看代码文件。