2013-05-08 141 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区分)