Git init--裸-不在工作树上工作

Git init--裸-不在工作树上工作,git,Git,我在下面举几个例子 基本上我想创建一个git repo,我可以从我的桌面推送到服务器上。。。 在主机上: 然后在当地: [local ~]$ cd project [local project]$ git init [local project]$ touch .gitignore [local project]$ git add . [local project]$ git commit 在主机上,如果我将CD放入目录。。我看到以下文件(通常位于.git目录中) 在本地,我然后创建一个远程

我在下面举几个例子

基本上我想创建一个git repo,我可以从我的桌面推送到服务器上。。。 在主机上:

然后在当地:

[local ~]$ cd project
[local project]$ git init
[local project]$ touch .gitignore
[local project]$ git add .
[local project]$ git commit
在主机上,如果我将CD放入目录。。我看到以下文件(通常位于.git目录中)

在本地,我然后创建一个远程推送: git远程添加源ssh://XXX@XXX/主页/XXX/XXX/ 它说它已经成功了

Counting objects: 3, done.
Writing objects: 100% (3/3), 210 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
但是,当我回到服务器上的工作文件夹时,那里什么也没有。。它只是上面列出的.git文件

我以前做过,它是这样工作的。。。就在这一次,我一定是做错了什么

更新

如果我尝试在没有--bare的情况下在服务器上创建repo。。。然后我在推送时得到这个错误

remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
更新和解决方案

我发现这个效果非常好


基本上使用一个--bare-then-have钩子将您的最新提交复制到一个工作目录

你所看到的似乎是正确的。您在该文件夹中看到的.git文件(其中很多在objects目录中)包含您的所有git存储库


当您创建一个“裸”存储库时,这会阻止其他任何人直接在那里(在您的主机上)编辑文件,而不将项目与您的所有源文件一起签出是阻止此类编辑的原因之一。

您看到的似乎是正确的。您在该文件夹中看到的.git文件(其中很多在objects目录中)包含您的所有git存储库


当您创建“裸”存储库时,这会阻止其他任何人直接在那里(在您的主机上)编辑文件,而不将项目与所有源文件一起签出是阻止此类编辑的原因之一。

git init--bare
创建“裸”存储库存储库-没有与之关联的工作目录的存储库。你所看到的是你所期待的。如果您想要一个单独的存储库,其中有一个已签出的工作目录与之关联,请不要使用
--bare
选项,但请注意,这样做会产生额外的影响,因为当远程存储库不是裸机存储库时,
git push
的行为会有所不同,为了保护您不丢失您在远程中可能有的任何未老化/未提交的更改。

git init--bare创建一个“bare”存储库,该存储库没有与之关联的工作目录。你所看到的是你所期待的。如果您想要一个单独的存储库,其中有一个已签出的工作目录与之关联,请不要使用
--bare
选项,但请注意,这样做会产生额外的影响,因为当远程存储库不是裸机存储库时,
git push
的行为会有所不同,为了保护您不丢失您在遥控器中可能有的任何未过期/未提交的更改。

谢谢,那么我这样做是不是错了?本质上,我只是想让远程文件夹可以推送到我可以从本地命令推送到的地方,而你已经做到了这一点。只是一个裸存储库处理其内容的方式与本地工作代表不同。因此,您不会看到您期望的文件。这没什么问题。@ThomAS谢谢,那么我如何“查看”这些文件呢?那条路是什么?你看不到他们。这不是一个裸体代表的目的。如果你想查看文件,你可以a)查看一个单独的工作目录B)首先不要使用裸体代表。就像托马斯说的。。。要“查看”文件,您必须在另一个位置克隆存储库。也许还有其他方法,但那是目前为止最简单的。谢谢,那么我是不是用错了方法?本质上,我只是想让远程文件夹可以推送到我可以从本地命令推送到的地方,而你已经做到了这一点。只是一个裸存储库处理其内容的方式与本地工作代表不同。因此,您不会看到您期望的文件。这没什么问题。@ThomAS谢谢,那么我如何“查看”这些文件呢?那条路是什么?你看不到他们。这不是一个裸体代表的目的。如果你想查看文件,你可以a)查看一个单独的工作目录B)首先不要使用裸体代表。就像托马斯说的。。。要“查看”文件,您必须在另一个位置克隆存储库。可能还有其他的方法,但这是目前为止最简单的方法。这取决于使用案例-我的许多项目都有一个普通的存储库和一个我推送到作为备份的裸存储库。一些数据库有多个正常的存储库和工作目录,所以我可以在任何一个地方工作,但我通常不会从这些存储库中推送,而是通过获取/合并来获取更新。通常在这些情况下,我也会有一个空的存储库来进行备份。好的,我真正想要的是一个远程回购,一个本地回购。因此,我可以git推动remote master将代码从本地移动到服务器在这种情况下,您的原始设置(bare remote repo)可能是最好的,但您将无法在远程中浏览代码-您仍然可以执行
git log
和其他操作来浏览修订历史记录。如果出于某种原因需要查看远程上的代码,您可以创建一个具有工作目录的一次性非裸克隆。通常裸repo用于交换代码或成为“幸运的存储库”。例如,您可以让多个开发人员在同一个项目和同一repo上工作,但他们都推到一个“中心”裸回购。不建议推送到非裸repo。有一些工具允许您浏览裸repo上的代码,如CGIT、gitweb等。每次需要从裸repo中取出代码进行部署时,您只需从裸repo中克隆/提取代码即可。不建议推送到非裸回购。这取决于使用情况-我的许多项目都有一个普通存储库和一个裸存储库,我推送到其中作为备份。一些数据库有多个正常的存储库和工作目录,所以我可以在任何一个地方工作,但我通常不会从这些存储库中推送—相反,我会获取/合并到ge
Counting objects: 3, done.
Writing objects: 100% (3/3), 210 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.