简体   繁体   English

git-remote:致命:使用post-receive钩子,您处于尚未出生的分支上

[英]git - remote: fatal: you are on a branch yet to be born, using post-receive hook

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: 因此,我尝试将github分支同步到网站的两个部分,理论上,我github中的master分支应该与我的网站tinyweatherstation.com同步,而beta分支应该与beta.tinyweatherstation.com同步,并且我已经成功地获得了后接收钩子与master分支一起使用,但是对于beta分支则为:

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

I get the error: 我收到错误:

    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

I have commited to this branch (beta) so I know it is there, so please help... 我已提交到此分支(测试版),所以我知道它在那里,所以请帮助...

  • Fetch all repository: 获取所有存储库:

     $ git remote add live_beta ssh://wesley@tinyweatherstation.com/var/www/tinyweatherstation.com.git $ git fetch --all 
  • Create and checkout to beta branch with remote's beta branch history ( make sure no local beta branch exists): 创建和检验,以beta分支与遥控器的beta分支历史(确保没有本地beta分支存在):

     $ git checkout beta 
  • Push to live_beta repo's beta branch: 推送到live_beta repo的beta分支:

     $ git push live_beta beta 

The error message comes from the target of the push (the Git there). 错误消息来自推送目标(那里的Git)。 Given that your post-receive hook is the simple one line expression: 假设您的接收后挂钩是简单的单行表达式:

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

this means that the Git living at: 这意味着Git居住在:

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

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. 也就是说,该(可能是裸机)存储库的当前分支具有一些名称,例如master ,但该分支名称尚不存在。

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

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知道的名称检查beta ,而不是当前的分支(再次,可能master -从这里开始,我就认为它 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 ). 另一个方法是在该Git存储库中(在服务器上的tinyweatherstation.com/var/www/beta.tinyweatherstation.com.git创建分支名称master tinyweatherstation.com/var/www/beta.tinyweatherstation.com.git There are multiple ways to do this: eg, 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. 有多种方法可以执行此操作:例如,您可以登录该计算机,导航至裸仓库,然后使用git branch将名称master指向任何现有提交,因为该仓库中已有一些提交。 Or, from your client machine, you could do another git push , but this time, do one that pushes to the name master : 或者,可以从客户端计算机执行另一次git push ,但这一次,执行一次将其推送到名称master

client$ git push live_beta master

(assuming you want the server's master to point to the same commit that your client's master points-to). (假设您希望服务器的master服务器指向客户端master服务器指向的同一提交)。

Yet another way is to log in to the server and change the name to which its HEAD points symbolically, ie, to change the name of the current branch on the tinyweatherstation.com server: 还有另一种方法是登录服务器并更改其HEAD象征性指向的名称 ,即,更改tinyweatherstation.com服务器上当前分支的名称

server$ git symbolic-ref HEAD refs/heads/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指的是您之前推送的分支。

Note that using git checkout -f beta will, as a side effect, set the current branch to beta . 请注意,使用git checkout -f beta作为副作用,会将当前分支设置 beta

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM