2014-02-27 82 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',但结果相同。 –