Heroku/Git:协议错误:坏的行长度字符:错误

5
当我通过Git部署到Heroku时,Slug构建成功完成,但之后我遇到了一个Git协议错误:
$ git push heroku -f v0.0.20:refs/heads/master

(...)    

remote: -----> Compressing...
remote:        Done: 55.3M
remote: -----> Launching...
remote:        Released v40
remote:        https://....herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
fatal: protocol error: bad line length character: erro
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'https://git.heroku.com/....git'

我尝试过手动SSH到git服务器来调试,但是没有成功,由于SSL的原因,tcpdump是无用的。

ssh git@heroku.com "git-upload-pack ....git"没有产生任何可疑的结果:

00c93a701c509d5730ba92e91463707699721929d477 HEADmulti_ack thin-pack side-band side-band-64k ofs-delta shallow no-progress include-tag multi_ack_detailed symref=HEAD:refs/heads/master agent=git/1.9.1
003f3a701c509d5730ba92e91463707699721929d477 refs/heads/master
0000

我联系了Heroku支持团队,他们尝试将相同的代码推送到相同的应用程序,但是这次却成功了。

如果您有任何关于如何调试此问题的建议,我将不胜感激。

2个回答

3

很难调试这个,但与此同时我找出了问题所在:

我使用以下命令推送代码:

git push heroku -f v0.0.20:refs/heads/master

将远程地址从HTTPS URL更改为SSH URL后,我收到了一个有用的错误消息:error: Trying to write non-commit object a3ab0fb2fda8d778850b3cbfc88e7e865d95daac to branch refs/heads/master

这让我意识到,我不能将git标签对象推送到远程分支引用。

针对这个问题有一个简单的解决方案:

git push heroku -f v0.0.20^{}:refs/heads/master

来自 gitrevisions 手册:

<rev>^{},例如 v0.0.20^{} 后缀 ^ 加上空的大括号 ({}) 表示对象可能是一个标签,并递归地解引用该标签,直到找到非标签对象为止。

换句话说:查找标签引用的最后一次提交。


0

我在使用Bitbucket管道将代码部署到Heroku时遇到了同样的错误。

git push https://heroku:${HEROKU_KEY}@git.heroku.com/${HEROKU_HMG_REMOTE}.git hmg:master
fatal: protocol error: bad line length character: erro

我原本以为无法解决这个问题,但是过了一周再次查看后,我意识到只需要在我的bitbucket-pipelines.yml中的push命令后添加-f即可。

pipelines:
  branches:
    hmg:
      - step:
          name: push_bitbucket
          script:
            - git push https://heroku:${HEROKU_KEY}@git.heroku.com/${HEROKU_HMG_REMOTE}.git hmg:master -f

我建议在使用--force时要非常小心,特别是在CI管道上。在我看来,接受的答案的第二个命令(使用^{})应该可以在不需要强制推送的情况下工作。 - Leonardo Dagnino

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接