使用git + post-receive hook管理网站:错误推送更改 [英] Managing website using git + post-receive hook: error pushing changes

查看:153
本文介绍了使用git + post-receive hook管理网站:错误推送更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的情况:


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


  1. 我在开发服务器上设置git,以便在我推送本地更改时,将它们添加到分离的工作树中(如在这里描述,很像 git status
  2. )。 code>),因为git找不到工作树。
  3. 我问过SO和得到了提示,我需要设置 bare = false 在我的配置文件中并指定工作树。 Sweet。

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

  $ git push origin master 
xxxx@xxx.xxx.xxx.xxx的密码:
计数对象:26,完成。
使用多达4个线程的增量压缩。
压缩对象:100%(18/18),完成。
写作对象:100%(18/18),2.56 KiB,完成。
共18(delta 8),重用0(delta 0)

remote:错误:拒绝更新检出分支:refs / heads / master
remote:error:By默认情况下,更新非裸仓库中的当前分支
remote:错误:被拒绝,因为它会使索引和工作树不一致
remote:错误:您推送的内容为 git reset --hard'匹配
remote:error:工作树到HEAD。
remote:错误:
remote:错误:您可以在远程存储库中将'receive.denyCurrentBranch'配置变量设置为
remote:error:'ignore'或'warn',以允许推入
remote:错误:当前分支;然而,除非你
remote:error:安排它更新它的工作树来匹配你在
remote:error:other方面推送的内容,否则不建议这样做。
remote:error:
remote:error:为了压制此消息并保持默认行为,请将
remote:error:'receive.denyCurrentBranch'配置变量设置为'拒绝'。

以ssh://xxxx@xxx.xxx.xxx.xxx/xxx/xxx/xxxxxx.git
! [remote rejected] master - > master(分支目前已检出)
错误:未能将某些参考推送到'ssh://xxxx@xxx.xxx.xxx.xxx/xxx/xxx/xxxxxx.git'

我发现这个其他用户有相同的问题。不幸的是,为他工作的解决方案是在他的配置中设置 bare = true ,这会重现我在上面第3步中遇到的问题。



错误消息表明
$ b


您可以将'receive.denyCurrentBranch'配置变量设置为
remote :错误:'忽略'或'警告'

在我的情况下,可以这样做吗?这对我来说听起来很不错,但是我对git不够熟悉,但当它出现时,它还没有意识到一个坏主意......

编辑



为了说清楚,我已经添加了一个post-receive钩子,并且运行正常。问题是我似乎必须在 bare = true (并能够推送到dev服务器)和 bare = false code>(并且能够在dev服务器上运行git命令)。

解决方案

我已经制定了一个解决方案是可以接受的,但不是很理想。基本上,我只是通过编辑我的配置文件来避开这个问题,当我需要将更改推送到我的实时服务器。



配置文件允许开发人员将本地更改dev:

  [core] 
repositoryformatversion = 0
filemode = true
bare = true

配置文件,当推送dev改变直播时:

  [core] 
repositoryformatversion = 0
filemode = true
bare = false
worktree = /var/www/example.com / httpd /

优点


  1. 有效

  2. 一旦我改变了配置文件以推动生存,repo被锁定,其他开发人员无法推送更改
  3. li>
  4. 由于我必须登录dev才能处理数据库迁移,因此不是一个大问题

缺点:基本上就是这样如果我知道如何正确地做到这一点,我肯定可以实现自动化。



注意:我喜欢@ vonC建议设置post-recieve挂钩有条件地推送到现场服务器。对接收后的钩子进行更改非常简单,但我不明白钩子会响应的触发器是什么。我很乐意听到建议,但:)

Question: How do I push my local commits to my development server if that worktree is not bare?

My Situation:

  1. I set up git on my development server so that when I push local changes, they are added to a detached working tree (as described here and much like this post).
  2. I then experienced problems running git on the dev server (eg, git status) because git could not find the working tree.
  3. I asked around SO and got the tip off that I needed to set bare = false in my config file and specify the worktree. Sweet.

But now when I try to push my commits to the dev server I get this error:

$ git push origin master
xxxx@xxx.xxx.xxx.xxx'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://xxxx@xxx.xxx.xxx.xxx/xxx/xxx/xxxxxx.git
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'ssh://xxxx@xxx.xxx.xxx.xxx/xxx/xxx/xxxxxx.git'

I see that this other user had the same problem. Unfortunately, the solution that worked for him was setting bare = true in his config, which would recreate the problem I was having in step 3 above.

The error message says

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

In my case, is it ok for me to do this? It sounds good to me, but I'm not familiar enough with git yet to recognize a bad idea when it comes around...

EDIT

Just to be clear, I have already added a post-receive hook and it's working smoothly. The problem is that I seem to have to choose between bare=true (and being able to push to the dev server) and bare=false (and being able to run git commands on the dev server).

解决方案

I've worked out a solution that is acceptable, but not quite ideal. Basically, I am just circumventing the problem by editing my config file when I need to push dev changes to my live server.

Config file which allows developers to push local changes to dev:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = true

Config file when pushing dev changes to live:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        worktree = /var/www/example.com/httpd/

Pros

  1. Works
  2. Once I have changed the config file to push to live, the repo is 'locked' and other developers cannot push changes
  3. Not a huge problem since I have to login to dev to handle database migration anyway

Cons: basically just that it's work that I'm sure could be automated, if I knew how to do it correctly.

Note: I like @vonC's suggestion of setting up the post-recieve hook to conditionally also push to the live server. Making the changes to the post-recieve hook is simple enough, but I do not understand what the trigger would be that the hook would respond to. I'd love to hear suggestions though : )

这篇关于使用git + post-receive hook管理网站:错误推送更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆