2014-02-27 81 views
0

我有一臺安裝了Git的Linux服務器。我正在開發一個Web應用程序,我想在網站路徑(/ var/www/apps/myapp)上的服務器上創建一個git存儲庫,然後將我的本地存儲庫更改推送到它。使用非裸Git存儲庫更新服務器文件

當我創建了服務器非純倉庫,推動了變化,我得到這個錯誤:

Refusing to update checked out branch: refs/heads/master. By default, updating the current branch in a non-bare repository is denied, because it will make the index and work tree inconsistent with what you pushed, and will require 'git reset --hard' to match the work tree to HEAD. etc.

它建議使用裸存儲庫。我可以成功地做到這一點,但我的問題是,我希望我的服務器在推送更改時自動更新Web應用程序文件夾。據我瞭解,當我使用裸存儲庫時,我必須再次在服務器上克隆裸存儲庫以獲取真實文件。這樣我有3個存儲庫。兩個在服務器端(其中一個是裸露的),另一個在本地。

我只想要一個只讀存儲庫,我可以推送我的更改並更新服務器端的Web應用程序文件夾內容。

解決方案是什麼?

回答

0

在服務器repo中,您必須允許推送到當前分支。從git help config摘錄:

receive.denyCurrentBranch

If set to true or "refuse", git-receive-pack will deny a ref update to the currently >checked out branch of a non-bare repository. Such a push is potentially dangerous because >it brings the HEAD out of sync with the index and working tree. If set to "warn", print a >warning of such a push to stderr, but allow the push to proceed. If set to false or >"ignore", allow such pushes with no message. Defaults to "refuse".

所以在服務器混帳回購協議:

git config receive.denyCurrentBranch ignore 

在服務器上,在.git/hooks/重命名post-receive.samplepost-receive並添加以下行吧:

export GIT_DIR=`pwd` 
cd .. 
export GIT_WORK_TREE=`pwd` 
git reset --hard HEAD 

這會在您推送時更新網站。

+0

數據丟失不危險嗎? –

+0

還有一些觀點:1)我沒有post-receive.sample,但有update-update後的樣例。 2)'pwd'是什麼意思? –

+0

我使用'git push -f origin master',但結果相同。 –