推送空裸git存储库失败

时间:2015-04-30 11:26:54

标签: git ssh travis-ci

在Travis CI构建期间,我需要将我的代码推送到在稍后部署代码的机器上运行的可能为空的裸git存储库。

主机上,我初始化了裸git存储库:

$ git init --bare
Initialized empty Git repository in /home/user/stuff.git/

设置了SSH密钥等,SSH正在运行。

客户端计算机(本例中为Travis CI)上,我执行此操作并收到错误消息。我已经尝试清除远程仓库并再次初始化它。有人有想法解决这个问题吗?

$ git remote add $HOST user@$FQDN:stuff.git
$ git push -f $HOST $BRANCH (I have also tried without force-push)
Counting objects: 375, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (188/188), done.
Writing objects: 100% (375/375), 3.18 MiB | 0 bytes/s, done.
Total 375 (delta 171), reused 375 (delta 171)
error: Could not read 6e841a138c7b1e36db81bbbf7815336369766b81
fatal: Failed to traverse parents of commit a27fd5c2101fc69107f51c0ad895108edec3ac46
error: Could not read 6e841a138c7b1e36db81bbbf7815336369766b81
fatal: Failed to traverse parents of commit a27fd5c2101fc69107f51c0ad895108edec3ac46
To user@host:stuff.git
 ! [remote rejected] master -> master (missing necessary objects)
error: failed to push some refs to 'user@host:stuff.git'

EDIT2:

环境变量引用:

$HOST=myserver
$FQDN=$HOST.mycompany.com
$BRANCH=master

EDIT1:

fsck on client repo(Travis CI)

$ git fsck
Checking object directories: 100% (256/256), done.
Checking objects: 100% (453/453), done.

fsck on remote repo(在推送之前,直接在git init --bare之后)

$ git fsck
notice: HEAD points to an unborn branch (master)
Checking object directories: 100% (256/256), done.
notice: No default references

fsck on remote repo(推送后)

$ git fsck
notice: HEAD points to an unborn branch (master)
Checking object directories: 100% (256/256), done.
Checking objects: 100% (453/453), done.
notice: No default references
dangling commit 95d0bbce235f8317f849a0766cca6604ac334c21

1 个答案:

答案 0 :(得分:1)

我找到了解决方案。

Travis CI似乎在构建时做了一个浅层克隆。至少Codeship正在这样做以增加git clone操作:https://codeship.com/documentation/faq/push-to-remote-repositories/

所以在推到裸仓之前,我做了

git fetch --unshallow || true
git fetch origin "+refs/heads/*:refs/remotes/origin/*"
...
git push -f $HOST $BRANCH

现在git push运行顺利。如果我错了,请纠正我。