2013-05-08 145 views
4

我在一個Web開發團隊工作。我們每個人在開發服務器上的主目錄中都有一個個人網站。通過Git部署網站

我們希望將它們轉換爲git工作倉庫,以便我們可以分支,重新分配並且一般享受git善良的好處。

在網上閱讀,有一對夫婦的選擇:

1)創建一個裸露的回購協議是同步到在WWW工作回購/通過後收到鉤

2)直接推到工作回購

選項1的問題是它處理分支不好。當我們推送除主站之外的分支時,post-receive hook仍然只會同步master,因此我們的更改不會出現在開發站點上。

問題與選項2是git不允許推送到檢出分支,以防止分離HEAD狀態。

在網絡中,「最佳實踐」解決方案選項2的周圍閱讀是這樣的:

上的客戶端推送1)爲了對服務器合併虛擬虛擬分支

2)進入主.. BUZZZZ錯誤答案。假定最終用戶沒有對服務器的shell訪問權限。

所以我想,「沒問題,只需創建一個後收到鉤像這樣」:

#!/bin/bash 
read oldSHA newSHA branch 
git merge $branch 

現在,這裏的怪異的一部分:當後收到鉤執行I得到

Please, commit your changes or stash them before you can merge. 

是的,我已經確認master是服務器上的簽出分支,並且假分支已經正確更新。當我直接在服務器上運行相同的命令(git merge dummy)時,一切正常。

任何人都可以解釋爲什麼嗎?

在此先感謝。

編輯1

這裏是git的狀態的結果,無論是前期的合併,後合併

Counting objects: 5, done.                                        
Delta compression using up to 8 threads. 
Compressing objects: 100% (3/3), done. 
Writing objects: 100% (3/3), 307 bytes, done. 
Total 3 (delta 2), reused 0 (delta 0) 
remote: **** PRE MERGE **** 
remote: # On branch master 
remote: # Untracked files: 
remote: # (use "git add <file>..." to include in what will be committed) 
remote: # 
remote: #  COMMIT_EDITMSG 
remote: #  FETCH_HEAD 
remote: #  HEAD 
remote: #  ORIG_HEAD 
remote: #  config 
remote: #  description 
remote: #  hooks/ 
remote: #  index 
remote: #  info/ 
remote: #  logs/ 
remote: #  objects/ 
remote: #  packed-refs 
remote: #  refs/ 
remote: no changes added to commit (use "git add" and/or "git commit -a") 
remote: error: Your local changes to the following files would be overwritten by merge: 
remote:   index.htm 
remote: Please, commit your changes or stash them before you can merge. 
remote: Aborting 
remote: **** POST MERGE **** 
remote: # On branch master 
remote: # Changes not staged for commit: 
remote: # (use "git add <file>..." to update what will be committed) 
remote: # (use "git checkout -- <file>..." to discard changes in working directory) 
remote: # 
remote: #  modified: index.htm 
remote: # 
remote: # Untracked files: 
remote: # (use "git add <file>..." to include in what will be committed) 
remote: # 
remote: #  COMMIT_EDITMSG 
remote: #  FETCH_HEAD 
remote: #  HEAD 
remote: #  ORIG_HEAD 
remote: #  config 
remote: #  description 
remote: #  hooks/ 
remote: #  index 
remote: #  info/ 
remote: #  logs/ 
remote: #  objects/ 
remote: #  packed-refs 
remote: #  refs/ 
remote: no changes added to commit (use "git add" and/or "git commit -a") 

注意,我可以做一個人工添加的git,git的承諾-m 「富」,並重新做這個過程有相同的結果

+0

當您收到此消息,這樣做:'git的status'。並告訴我們結果。 – Tadeck 2013-05-08 21:12:24

+0

另一種考慮的方法是使用['git archive'](http://git-scm.com/docs/git-archive)並將檔案解壓縮到您的實際站點目錄中(不要將它們作爲存儲庫)。你應該可以在一個隱藏的repo中的'post-receive'鉤子中做到這一點。 你想如何決定使用什麼分支?它應該是什麼分支最近的提交? – 2013-05-08 21:41:09

+0

是的,我想提交最新的分支。應該是什麼傳遞給接收包後收到。真的,我想顯示爲調試目的推送的最新分支。 – vaFyreHeart 2013-05-08 22:42:14

回答

2

在那些「DUH!」之一。時刻,我意識到我可以使用選項1,只是通過分支名稱,就像我試圖與選項2.

所以,我創建了/ home /用戶名/ www和增加了一個後收到鉤/home/username/www.git看起來是這樣的:

#!/bin/bash 
read oldSHA newSHA branch 
git --git-dir="/home/username/www/.git" --work-tree="/home/username/www" pull /home/username/www.git $branch 

然後,我改變了我的遙控器SSH://[email protected]/home/用戶名/ WWW。git(光禿禿的,不是工作的),並推送到該遠程通過:

git push remoteName branchName 

瞧!一切正常。

由於我使用目錄名稱的一些錯誤陷阱和變量(因此它們可以部署到任何用戶),實際的接收後代碼更加複雜,但您明白了。

(要小心閱讀代碼樣本時,WWW/git的和www.git區分)