将本地推送到服务器时出现Git问题

将本地推送到服务器时出现Git问题,git,Git,我有一个本地git回购协议,该协议已初始化为: $git init 我想把它推到开发服务器上 这是dev服务器上的de目录结构: ROOT/public\u html ROOT/public_html.git 在public_html.git中,我使用以下方法初始化了一个裸回购: $git init --bare 然后我创建了一个post接收挂钩: #!/bin/sh GIT_WORK_TREE=/home/path/to/public_html 在本地计算机上,我添加了远程: $git r

我有一个本地git回购协议,该协议已初始化为: $git init

我想把它推到开发服务器上

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

在public_html.git中,我使用以下方法初始化了一个裸回购:

$git init --bare
然后我创建了一个post接收挂钩:

#!/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
检查post-receive钩子工作是否会给我消息: 致命:你在一根尚未出生的树枝上

我已经在谷歌上搜索了这个错误消息,但是弹出的几个页面并没有太大帮助

将配置文件更改为:

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

所以,嗯,我有点卡住了:)

您在post receive脚本中设置的变量只在该脚本中工作

第二种方法行不通,因为git就是这样工作的


如果确实需要,请在post receive脚本中从本地裸存储库显式签出。不要设置工作树。

第二种方法不是我喜欢的方法,但是它确实帮助我将文件从repo获取到工作树。问题是推送到远程repo不会更新工作树中的文件,工作树是在post-receive钩子中设置的。它显示消息:
致命:您在一个尚未出生的分支上
。当然,有一次:
git clone public\u html.git public\u html
我试过:
git\u WORK\u TREE=/home/path/to/public\u html git checkout
git\u WORK\u TREE=/home/path/to/public\u html git checkout-f
。同样的错误:
致命:您在一个尚未出生的分支上
啊,等等,没有看到您的最后一条消息。现在就试试!