git-remote:致命:使用post-receive钩子,您处于尚未出生的分支上 [英] git - remote: fatal: you are on a branch yet to be born, using post-receive hook

查看:118
本文介绍了git-remote:致命:使用post-receive钩子,您处于尚未出生的分支上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我尝试将github分支同步到我网站的两个部分,理论上是我 github 应该与我的网站 tinyweatherstation.com 同步,并且Beta分支应该与 beta.tinyweatherstation.com ,并且我已经成功获得了与master分支配合使用的接收后挂钩,但是当它用于beta时分支:

So I am trying to sync to github branches to two parts of my website, theoretically the master branch in my github should be synced with my website tinyweatherstation.com and the beta branch should sync with beta.tinyweatherstation.com, and I have successfully gotten the post-receive hook working with the master branch, but when this for the beta branch:

git remote add live_beta ssh://wesley@tinyweatherstation.com/var/www/tinyweatherstation.com.git
git push live_beta +beta:refs/heads/beta

我得到了错误:

    Enter passphrase for key '/c/Users/WesleyN/.ssh/id_rsa':
Counting objects: 999, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (967/967), done.
Writing objects: 100% (999/999), 5.04 MiB | 529.00 KiB/s, done.
Total 999 (delta 360), reused 0 (delta 0)
remote: Resolving deltas: 100% (360/360), done.
remote: fatal: You are on a branch yet to be born
To ssh://tinyweatherstation.com/var/www/beta.tinyweatherstation.com.git
 * [new branch]      beta -> beta

帖子接收挂钩看起来像这样...

The post receive hook looks like this...

#!/bin/sh GIT_WORK_TREE=/var/www/beta.tinyweatherstation.com/html git checkout -f

#!/bin/sh GIT_WORK_TREE=/var/www/beta.tinyweatherstation.com/html git checkout -f

我已经提交了此分支(测试版),所以我知道它在那里,所以请帮助...

I have commited to this branch (beta) so I know it is there, so please help...

推荐答案

错误消息来自推送目标(那里的Git).鉴于您的post-receive钩子是简单的单行表达式:

The error message comes from the target of the push (the Git there). Given that your post-receive hook is the simple one line expression:

GIT_WORK_TREE=/var/www/beta.tinyweatherstation.com/html git checkout -f

这意味着Git居住在:

this means that the Git living at:

ssh://tinyweatherstation.com/var/www/beta.tinyweatherstation.com.git

正如错误消息所说,

是在尚未诞生的分支上".也就是说,该(可能是裸机)存储库的 current 分支具有一些名称,例如master,但是该分支名称尚不存在.

is, just as the error message says, "on a branch yet to be born". That is, the current branch of that (presumably bare) repository has some name, such as master, but that branch name does not yet exist.

有多种解决方案.一种是选择一个显式分支进行检出:

There are multiple solutions. One is to pick an explicit branch to check out:

GIT_WORK_TREE=/var/www/beta.tinyweatherstation.com/html git checkout -f beta

这样,这个特定的Git知道使用名称beta而不是其当前分支进行检出(同样,可能是master-从这里开始,我将假定它 master)实际上还不存在.

That way, this particular Git knows to check out by the name beta rather than its current branch (again, probably master—from here on, I'll assume that it is master) that does not actually exist yet.

另一种方法是在该Git存储库中(在服务器上的tinyweatherstation.com/var/www/beta.tinyweatherstation.com.git)创建分支名称master.有多种方法可以执行此操作:例如,您可以登录该计算机,导航至裸仓库,然后使用git branch将名称master指向任何现有的提交,因为现在已有一些提交在存储库中.或者,您可以在客户端计算机上执行另一个git push,但是这次,执行一次将其推入名称master的操作:

Another is to create the branch name master in that Git repository (on the server at tinyweatherstation.com/var/www/beta.tinyweatherstation.com.git). There are multiple ways to do this: e.g., you could log in on that machine, navigate to the bare repository, and use git branch to make the name master point to any of the existing commits, now that there are some commits in the repository. Or, from your client machine, you could do another git push, but this time, do one that pushes to the name master:

client$ git push live_beta master

(假设您希望服务器的master指向客户端的master指向的同一提交).

(assuming you want the server's master to point to the same commit that your client's master points-to).

另一种方法是登录服务器并更改其HEAD象征性指向的名称,即,更改tinyweatherstation.com服务器上当前分支的 name :

Yet another way is to log in to the server and change the name to which its HEAD points symbolically, i.e., to change the name of the current branch on the tinyweatherstation.com server:

server$ git symbolic-ref HEAD refs/heads/beta

现在,没有分支名称的git checkout -f将起作用,因为名称beta指的是您之前推送的分支.

Now the git checkout -f with no branch name will work, because the name beta refers to the branch you pushed earlier.

请注意,使用git checkout -f beta作为副作用,会将当前分支设置为 beta.

Note that using git checkout -f beta will, as a side effect, set the current branch to beta.

这篇关于git-remote:致命:使用post-receive钩子,您处于尚未出生的分支上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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