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

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

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

gitversion-controlgithub

提问by Aatish Molasi

I'm a newbie when it comes to git and i went through some video tutorials here

我是 git 的新手,我在这里浏览了一些视频教程

After seeing these tutorials i tried to set up a git repo with my friend using ssh

看完这些教程后,我尝试使用 ssh 与我的朋友建立一个 git repo

Note:

笔记:

  • We are using mac snow leopard
  • The Git version is 1.7.5.4
  • 我们使用的是mac雪豹
  • Git 版本是 1.7.5.4

I managed to set up my code in a folder lets say 'folder1' using

我设法在文件夹中设置了我的代码,可以说“folder1”使用

git init

which has my code files .

其中有我的代码文件。

Then I create an empty repository on my friends machine lets say 'folder2', and I made folder2a bare repository using

然后我在我朋友的机器上创建了一个空的存储库,比如说“ folder2”,然后我使用了folder2一个裸存储库

git init --bare --shared

Now I wanted to setup the shared repo as the repository for folder1's code After this, I tried to add the remote on the bare repo using ssh

现在我想将共享存储库设置为folder1's 代码的存储库之后,我尝试使用 ssh 在裸存储库上添加远程

git remote add origin myFriend@hisIp:/LocationToFile

After this, I pushed the code which gave me a successful message

在此之后,我推送了给我成功消息的代码

Now the issue is that the git repo 'folder2' is still show an empty repo (with the folders of an empty repository) and I cant perform git operations in folder2as even if I do "git status", I get "fatal: This operation must be run in a work tree"

现在的问题是 git repo ' folder2' 仍然显示一个空的 repo(带有空存储库的文件夹),我无法执行 git 操作,folder2即使我执行“ git status”,我得到“ fatal: This operation must be run in a work tree

回答by VonC

Since it is a bare repo, it has no working tree. See "What's the -practical- difference between a Bare and non-Bare repository?".

由于它是一个裸仓库,它没有工作树。请参阅“裸存储库和非裸存储库之间的实际区别是什么?”。

You should clone locally that folder2 repo, in order to execute your commands.

您应该在本地克隆该文件夹 2 存储库,以便执行您的命令。

# on server:
cd /path/to/folder2
git clone folder2 folder2b
cd folder2b
git status

Note: It would be best to follow the naming convention for bare repo directory: folder2.git(instead of folder2)

注意:最好遵循裸仓库目录的命名约定:(folder2.git而不是folder2