git - 使用 git + post-receive hook 管理网站 : error pushing changes

标签 git web push

问题:如果该工作树不是空的,如何将本地提交推送到我的开发服务器?

我的情况:

  1. 我在开发服务器上设置了 git,以便当我推送本地更改时,它们会被添加到独立的工作树中(如 described here 和类似 this post )。
  2. 然后,我在开发服务器上运行 git 时遇到了问题(例如,git status),因为 git 找不到工作树。
  3. 我问了周围的人,然后got the tip off我需要在配置文件中设置 bare = false 并指定工作树。甜甜的。

但是现在当我尝试将我的提交推送到开发服务器时,我收到此错误:

$ git push origin master
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cbb3b3b3b38bb3b3b3e5b3b3b3e5b3b3b3e5b3b3b3" rel="noreferrer noopener nofollow">[email protected]</a>'s password:
Counting objects: 26, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (18/18), done.
Writing objects: 100% (18/18), 2.56 KiB, done.
Total 18 (delta 8), reused 0 (delta 0)

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

To ssh://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="552d2d2d2d152d2d2d7b2d2d2d7b2d2d2d7b2d2d2d" rel="noreferrer noopener nofollow">[email protected]</a>/xxx/xxx/xxxxxx.git
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'ssh://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0f777777774f777777217777772177777721777777" rel="noreferrer noopener nofollow">[email protected]</a>/xxx/xxx/xxxxxx.git'

我看到this other user had the same problem 。不幸的是,对他有效的解决方案是在他的配置中设置 bare = true,这会重现我在上面第 3 步中遇到的问题。

错误消息显示

You can set 'receive.denyCurrentBranch' configuration variable to remote: error: 'ignore' or 'warn'

就我而言,我可以这样做吗?这对我来说听起来不错,但我对 git 还不够熟悉,还没有意识到它出现时的坏主意......

编辑

需要明确的是,我已经添加了一个 post-receive Hook ,并且它运行顺利。问题是我似乎必须在 bare=true (并且能够推送到开发服务器)和 bare=false (并且能够运行 git开发服务器上的命令)。

最佳答案

为什么不:

  • 将您的提交推送到裸存储库
  • 在该开发存储库上设置一个接收后 Hook ,然后该 Hook 将转到非裸开发存储库并 checkout 正确的分支,从裸存储库中提取新的提交?

这就是 your link描述(使用分离的工作树),但它在裸存储库中设置了钩子(Hook):

$ mkdir /var/www/www.example.org
$ cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/var/www/www.example.org git checkout -f
$ chmod +x hooks/post-receive

关于git - 使用 git + post-receive hook 管理网站 : error pushing changes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10902551/

相关文章:

GIT:如何只恢复一个历史变化,同时保持其他历史变化?

web - Vagrant 主机端口被忽略

python - Django UserAdmin 的 add_fieldsets?

C# 林奇 : What is the difference between a Pull model and a Push model?

notifications - 基本计划的人可以发送推送通知吗?

git - 定义具有相同名称的 git 别名以 stash 原始命令

git - 有没有办法摆脱指向远程不存在分支的本地 'worktree' 文件夹

ruby - 是否有使用 Rugged 将所有内容添加到 Git 的特定协议(protocol)?

javascript - Ext JS SORTING (2, 5, 30, 100) 比较函数

sms - 发送wap推送