2012-07-17 60 views
1

在這裏,我下面的例子中 http://wiki.dreamhost.com/GitGit的初始化--bare - 對工作樹

基本上我想創建一個混帳回購協議,我可以推到一個服務器上,從我的桌面... 在主機不工作:

[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到目錄..我出以下文件主機(通常這LY坐在git的目錄)

HEAD branches config description hooks info objects refs 

在本地然後創建一個遠程推送: 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文件。

我以前做過這件事,它的工作方式是這樣的......只是這次我必須做錯事。

UPDATE

如果我試圖建立一個沒有--bare服務器上的回購...然後我得到推送

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然後有鉤子複製你的最新提交到工作目錄!

回答

2

git init --bare創建一個「裸」存儲庫 - 一個沒有與其關聯的工作目錄。你所看到的是預期的。如果您希望單獨的存儲庫具有與其關聯的檢出工作目錄,請不要使用--bare選項,但請注意,這樣做會產生額外的影響,因爲git push在遠程不是裸存儲庫時的行爲不同,以便保護您不會丟失您在遙控器中可能存在的任何未分配/未提交的更改。

+0

你會做什麼? – 2012-07-17 15:11:29

+0

取決於用例 - 我的許多項目都有一個正常的存儲庫,還有一個我將其作爲備份推向的裸露存儲庫。有幾個擁有多個工作目錄的普通存儲庫,所以我可以在任何地方工作,但我通常不會從這些工作目錄推送 - 而是通過取/合併來獲取更新。通常在這些情況下,我也會有一個裸倉庫來推動備份。 – twalberg 2012-07-17 15:16:35

+0

好吧,我真正想要的是一個遠程回購,一個本地。所以我可以用git推動遠程主服務器將代碼從本地服務器遷移到服務器 – 2012-07-17 15:18:57

3

你所看到的似乎是正確的。您在該文件夾中看到的.git文件(以及對象目錄中的很多文件)包含您的所有git存儲庫。

當你創建一個「裸露」的存儲庫時,這可以防止其他人直接在那裏(在你的主機上)編輯這些文件,而不是將你的源文件簽出來的項目是阻止這樣的事情之一編輯。

+0

謝謝,那麼我這樣做是錯誤的方式嗎?本質上,我只是想創建一個遠程文件夾pushable,我可以從本地 – 2012-07-17 14:49:07

+1

命令推你已經實現了。它只是一個裸倉庫處理其內容不同,然後當地的工作代表。因此你不會看到你期望在那裏的文件。沒有錯。 – 2012-07-17 14:57:57

+0

@ThomAS謝謝,那麼如何「查看」這些文件?什麼是路徑? – 2012-07-17 15:12:08