Git将本地推送到服务器的问题

时间:2014-03-13 14:45:17

标签: git

我有一个已经初始化的本地git仓库: $ git init

我想将其推送到开发服务器。

这是dev服务器上的de目录结构: ROOT /的public_html ROOT / public_html.git

在public_html.git中,我使用:

初始化了一个裸仓库
$git init --bare

然后我创建了一个post-receive hook:

#!/bin/sh
GIT_WORK_TREE=/home/path/to/public_html

在本地机器上我添加了遥控器:

$git remote add development ssh://location/public_html.git

然后我使用以下方法将本地仓库推送到遥控器:

$git push development master

这一切都奏效了,我得到了回购被成功推送的信息。

但是文件不会复制到工作树中。该目录中不存在任何文件。

使用命令: sh /hooks/post-receive检查收件后挂钩工作是否会给我留言: 致命的:你在一个尚未出生的分支上

我已经用Google搜索了这条错误消息,但弹出的几页并不是很有帮助。

将配置文件更改为:

[core]
bare = false 
worktree = /home/path/to/public_html/

会让我使用git checkout -f将文件复制到工作目录,但是从本地推送到开发会给我这个错误:

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'.

所以,呃,我有点卡住了。)

1 个答案:

答案 0 :(得分:0)

您在接收后脚本中设置的变量只能在该脚本中使用。

你的第二种方法不起作用,因为这就是git的工作原理。

如果您确实需要,请在收发后脚本中从本地裸存储库中明确签出。不要设置工作树。