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

时间:2012-07-17 14:41:56

标签: git

我在这里关注这些例子 http://wiki.dreamhost.com/Git

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

[host ~]$ mkdir project.git
[host ~]$ cd project.git
[host project.git]$ git init --bare
[host project.git]$ exit

然后在当地:

[local ~]$ cd project
[local project]$ git init
[local project]$ touch .gitignore
[local project]$ git add .
[local project]$ git commit

在主机上,如果我CD进入目录..我显示以下文件(通常位于.git目录)

HEAD  branches  config  description  hooks  info  objects  refs

在本地我然后创建一个远程推送: git remote add origin ssh:// XXX @ XXX / home / 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'.

更新和解决....

我发现这个效果非常好 http://toroid.org/ams/git-website-howto

基本上使用--bare然后使用hook将最新的提交复制到工作目录!

2 个答案:

答案 0 :(得分:3)

你看到的似乎是正确的。您在该文件夹中看到的.git文件(以及对象目录中的大量文件)包含您的所有git存储库。

当你创建一个“裸”存储库时,这会阻止任何其他人直接在那里编辑文件(在你的主机上),没有用你的所有源文件检出项目是阻止这种编辑的事情之一

答案 1 :(得分:2)

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

相关问题