Git 推送导致致命:协议错误:行长度错误字符:此

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22314298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:51:46  来源:igfitidea点击:

Git push results in fatal: protocol error: bad line length character: This

gitsshrepositorygitlab

提问by user3404044

I am trying to get GitLab working on my server (running CentOS 6.5). I followed the gitlab-receipeto the line, but I just can't get it working. I am able to access the web interface, create new projects but pushing to the master branch returns the following error :

我正在尝试让 GitLab 在我的服务器上运行(运行 CentOS 6.5)。我跟着gitlab-receipe到了线路,但我无法让它工作。我能够访问 Web 界面,创建新项目,但推送到 master 分支返回以下错误:

fatal: protocol error: bad line length character: This

I have done checks on the production environment, here are the results :

我对生产环境做了检查,结果如下:

Checking Environment ...

Git configured for git user? ... yes

Checking Environment ... Finished

Checking GitLab Shell ...

GitLab Shell version >= 1.7.9 ? ... OK (1.8.0)
Repo base directory exists? ... yes
Repo base directory is a symlink? ... no
Repo base owned by git:git? ... yes
Repo base access is drwxrws---? ... yes
update hook up-to-date? ... yes
update hooks in repos are links: ... 
ASC / Wiki ... repository is empty
Running /home/git/gitlab-shell/bin/check
Check GitLab API access: OK
Check directories and files: 
    /home/git/repositories: OK
    /home/git/.ssh/authorized_keys: OK
Test redis-cli executable: redis-cli 2.4.10
Send ping to redis server: PONG
gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Sidekiq ...

Running? ... yes
Number of Sidekiq processes ... 1

Checking Sidekiq ... Finished

Checking LDAP ...

LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab ...

Database config exists? ... yes
Database is SQLite ... no
All migrations up? ... yes
GitLab config exists? ... yes
GitLab config outdated? ... no
Log directory writable? ... yes
Tmp directory writable? ... yes
Init script exists? ... yes
Init script up-to-date? ... no
  Try fixing it:
  Redownload the init script
  For more information see:
  doc/install/installation.md in section "Install Init Script"
  Please fix the error above and rerun the checks.
projects have namespace: ... 
ASC / Wiki ... yes
Projects have satellites? ... 
ASC / Wiki ... can't create, repository is empty
Redis version >= 2.0.0? ... yes
Your git bin path is "/usr/bin/git"
Git version >= 1.7.10 ? ... yes (1.8.3)

Checking GitLab ... Finished

For the init script error, the receipt says

对于初始化脚本错误,收据说

Do not mind about that error if you are sure that you have downloaded the up-to-date

如果您确定已经下载了最新版本,请不要介意该错误

so as I have downloaded the latest one, I can't really do much about it.

所以当我下载了最新的时,我真的无能为力。

I've been banging my head for the past week, and can not figure out why this error is occurring, any help would appreciated!!

过去一周我一直在敲我的头,无法弄清楚为什么会发生这个错误,任何帮助将不胜感激!!

采纳答案by Argilium

If anyone else has this problem, the solution is to change the login shell of the user 'git' (or whatever your user is called) to /bin/bash. This can be done via the command : usermod -s /bin/bash git(Link). The reason for changing the login shell is because the default shell for the git user is /sbin/nologin(or similar, depending on environment), which prevents the git application from logging in as the git user on the git server.

如果其他人遇到此问题,解决方案是将用户 'git'(或您的用户的任何称呼)的登录 shell 更改为/bin/bash. :这可以通过命令来完成usermod -s /bin/bash git链接)。更改登录shell的原因是因为git用户的默认shell是/sbin/nologin(或类似的,取决于环境),这阻止了git应用程序在git服务器上以git用户身份登录。

回答by einverne

Just for other users reference:

仅供其他用户参考:

fatal: protocol error: bad line length character: no s
can be a truncated answer for "No such project".

As in my case, this kind of error can be fixed by adding user (even yourself) to the project in gitlab:

就我而言,可以通过将用户(甚至您自己)添加到 gitlab 中的项目来修复这种错误:

https://gitlab.com/username/your_project/project_members

https://gitlab.com/username/your_project/project_members

also, ensure your public key is set in your user Profile settings > SSH Key or in Project > Settings > Deploy Keys

另外,请确保您的用户中设置了您的公钥 Profile settings > SSH Key or in Project > Settings > Deploy Keys

https://gitlab.com/profile/keys

https://gitlab.com/profile/keys

回答by Erik Kruus

Another thing to check is that your .bashrc does not print extra stuff. For example 'echo "hello"' in .bashrc creates the error:

要检查的另一件事是您的 .bashrc 不会打印额外的内容。例如 .bashrc 中的 'echo "hello"' 会产生错误:

kruus@borg:~/malt$ ssh snake01
Last login: Tue Oct 21 10:44:31 2014 from 138.15.166.103
hello
...
kruus@snake01:/net/snake01/usr/hydra/kruus/malt$ git pull
fatal: protocol error: bad line length character: hell

Note how saying hello caused one hell of a problem.

请注意打招呼是如何导致一个大问题的。

Removing the 'echo "hello"' from my .bashrc allows git to work as expected again. You may need to ">& /dev/null" to remove output if your .bashrc does more complicated things.

从我的 .bashrc 中删除 'echo "hello"' 允许 git 再次按预期工作。如果你的 .bashrc 做更复杂的事情,你可能需要 ">& /dev/null" 来删除输出。

回答by dsc

Another possibility is that you misspelled the repository name.

另一种可能性是您拼错了存储库名称。

I've done it twice in the last two days. I added a remote and misspelled it and I misspelled the name when creating the project on GitLab.

在过去的两天里,我已经做了两次。我添加了一个遥控器并拼错了它,在 GitLab 上创建项目时我拼错了名称。

In both cases when I tried to push to remote I got

在这两种情况下,当我尝试推送到远程时,我得到了

fatal: protocol error: bad line length character: No s

So check that spelling!

所以检查拼写!

Also, if you create the project under a different name (like a group) make sure that's the remote you add.

此外,如果您以不同的名称(如组)创建项目,请确保这是您添加的遥控器。

回答by Gavin Gilmour

The solution to my issue with this was that I'd forgotten to add in a deploy key for the project (for the user I was trying to deploy as).

我的问题的解决方案是我忘记为项目添加部署密钥(对于我尝试部署的用户)。

Adding a deploy key in https://gitlab/group/project/deploy_keyssorted me out.

https://gitlab/group/project/deploy_keys 中添加部署密钥让我解决了问题。

回答by Borja Aparicio

You can get the actual error message by doing:

您可以通过执行以下操作来获取实际的错误消息:

ssh [email protected] "git-upload-pack yournamespace/yourreponame.git"

According to this git documentationgit protocol expects at the beginning of each line its size and then the content. Looks like GitLab doesn't do that and sends the error message directly.

根据这个 git 文档git 协议期望在每一行的开头是它的大小,然后是内容。看起来 GitLab 没有这样做并直接发送错误消息。

回答by sjorsvb

I experienced this error message today ("No s"), and it actually had to do with me having no rights to push to the targeted repository. Even though the error message is very weird, this might help people continue to work.

我今天遇到了这个错误消息(“No s”),这实际上与我无权推送到目标存储库有关。尽管错误消息非常奇怪,但这可能有助于人们继续工作。

We use Gitlab.

我们使用 Gitlab。

回答by mytydev

sudo gitlab-ctl reconfigure

and then

进而

sudo gitlab-ctl restart

should do the trick

应该做的伎俩

回答by hellcode

In my case (private key over ~/.ssh/config) I had to leave out the ssh part in:

在我的情况下(通过 ~/.ssh/config 的私钥)我不得不省略 ssh 部分:

git clone ssh://git@hostname:username/repository.git

It worked with:

它与:

git clone git@hostname:username/repository.git

Error message was:

错误消息是:

fatal: protocol error: bad line length character: No s

致命:协议错误:错误的行长字符:没有 s

回答by Chase Coney

In my case, my username was changed and this repository's git config was not updated to match the new name.

就我而言,我的用户名已更改,并且此存储库的 git 配置未更新以匹配新名称。

Check your git remotes to make sure they are pointing to correct place:

检查您的 git 遥控器以确保它们指向正确的位置:

git remote -v

git remote -v

Update the config by editing the config manually:

通过手动编辑配置来更新配置:

vim .git/config

vim .git/config

or through commands

或通过命令

git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git

git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git