git推送错误git-receive-pack [英] git push error git-receive-pack
问题描述
我在不同的网络上有两个git存储库。我一直在沟通他们两个没有问题,但由于某种原因,今天当我做一个混帐推,我得到以下错误:
------------------------------------------- ---
bash:git-receive-pack:找不到命令
致命:远端挂起意外
---------------- ------------------------------
我搜索了一下,并确保/ usr / local / bin在我的$ PATH中。这里是我的git的bin目录的输出:
pre $ $ $ $ $ ls -l / usr / local / git / bin /
总计16760
-rwxr-xr-x 1个根轮4329416 Mar 26 20:06 git *
-rwxr-xr-x 1个根轮14852 Mar 26 20:06 git-credential-osxkeychain *
-rwxr-xr-x 2根轮子162402 Mar 26 20:06 git-cvsserver *
lrwxr-xr-x 1根轮子4 Apr 3 11:02 git-receive -pack @ - > git
-rwxr-xr-x 2根轮子1830248 Mar 26 20:06 git-shell *
lrwxr-xr-x 1根轮子3 Apr 3 11:02 git-upload-archive @ - > ; git
-rwxr-xr-x 2根轮子1893064 Mar 26 20:06 git-upload-pack *
-rwxr-xr-x 1根轮子333121 Mar 26 20:06 gitk *
有什么想法可能会出错?
谢谢
--------------编辑-------------------
我在远程系统的.bashrc中有以下行:
export PATH = $ LOCAL / git -1.8 / bin /:$ PATH
这是远程机器上的输出:
$ ls $ LOCAL / git-1.8 / bin
git git -cvsserver gitk git-receive-pack git-shell git-upload -archive git-upload-pack
这是输出,当我执行ssh user @ remote env 从我的机器到远程机器:
[pradeep @ laptop〜] $ ssh k00603@k.rics.riken.jp env
SHELL = / bin / bash
SSH_CLIENT = 153.133.52.171 52379 22
USER = k00603
MAIL = / var / mail / k00603
PATH = / usr / local / bin目录:/ bin中:在/ usr / bin中:在/ usr / LOC / home / hp120242 / k00603
LOGNAME = k00603
SSH_CONNECTION = 153.133.52.171 52379 10.7.160.4 22
LC_CTYPE = en_US.UTF-8
_ = / bin / env
bash中缺少git路径。
编辑:以下是我的远程系统主目录中的.bash_profile:
#.bash_profile
#获取别名和函数
if [-f〜/ .bashrc];然后
。 〜/ .bashrc
fi
#用户特定的环境和启动程序
PATH = $ PATH:$ HOME / bin:$ LOCAL / git-1.8 / bin
$ b $ export PATH
你ssh进入一个盒子并得到一个提示,你实际上经历了一个与运行一个命令不同的过程。 Shell基于它是否是登录shell和/或它是否是交互式会话,具有有关配置来源的规则。尝试运行:
ssh user @ host env
这将打印您的环境,如非交互式登录会话所示。我的猜测是,在这种情况下, / usr / local / git / bin
不在路径中。您可以通过使用 - receive-pack
选项来解决此问题: git push
:
git push --receive-pack = / path / to / git-receive-pack
/ path / to / git-receive-pack
是 remote 机器。它告诉git在ssh进入远程时在哪里找到另一端。
最好的答案是修复你的shell配置,但这可能会很棘手,具体取决于贝壳。我主要使用ZSH,我通过设置一个〜/ .zshenv
来解决这个问题,它由ZSH在非交互式shell中获取。我认为事情往往不太清楚bash。您可能需要编辑您的〜/ .bashrc
和/或您的〜/ .bash_profile
。
假设你在远程端安装了vanilla Linux(可能是这种情况),并且它正在运行bash shell,最简单的解决方法是更改
.bashrc中
。编辑〜/ .bashrc
并添加: export PATH = / path / to / your / installed / git / bin:$ PATH
其中 / path / to / your / installed / git / bin
是在主目录中安装git的地方。我倾向于将本地安装放在〜/ .local / bin
中,所以我的看起来像:
export PATH = $ HOME / .local / bin:$ PATH
Your's可能只是:
export PATH = $ HOME / bin:$ PATH
你不说这个位置,所以我不能给你正确的表达方式。
在大多数系统上,即使向ssh提供了一个命令,也会产生 .bashrc
。进行此更改后,请再次尝试运行 ssh user @ host env
。你应该在路径变量中看到你保存git二进制文件的bin文件夹的位置。然后,您应该可以执行诸如 ssh user @ host git --version
之类的操作,并看到如下内容:
git version 1.8.2
如果您看到一个错误,那么您可能没有正确键入路径,或者当您登录到计算机时没有收到.bashrc。
.profile示例
#if running -bash
if [-n$ BASH_VERSION];那么
#include .bashrc(如果存在的话)
if [-f$ HOME / .bashrc];然后
。 $ HOME / .bashrc
fi
fi
#设置PATH,所以它包含用户的私人箱子(如果存在的话)
if [-d$ HOME / bin ];然后
PATH =$ HOME / bin:$ PATH
fi
自动使用 - receive-pack
假设您的远程名称为 origin
,你可以这样做:
git config --local remote.origin。 receivepack \
/ path / to / git-receive-pack / on / the / remote
<您可能还需要修正上传包:
git config --local remote.origin.uploadpack \
/ path / to / git-upload-pack / on / the / remote
I have two git repositories on different networks. I had been communicating between the two of them without problem but for some reason today when I am doing a "git push", I am getting the following error:
----------------------------------------------
bash: git-receive-pack: command not found
fatal: The remote end hung up unexpectedly
----------------------------------------------
I googled and made sure that the "/usr/local/bin" was in my "$PATH". Here is the output of the bin directory of my git:
[pradeep@laptop ]$ls -l /usr/local/git/bin/
total 16760
-rwxr-xr-x 1 root wheel 4329416 Mar 26 20:06 git*
-rwxr-xr-x 1 root wheel 14852 Mar 26 20:06 git-credential-osxkeychain*
-rwxr-xr-x 2 root wheel 162402 Mar 26 20:06 git-cvsserver*
lrwxr-xr-x 1 root wheel 3 Apr 3 11:02 git-receive-pack@ -> git
-rwxr-xr-x 2 root wheel 1830248 Mar 26 20:06 git-shell*
lrwxr-xr-x 1 root wheel 3 Apr 3 11:02 git-upload-archive@ -> git
-rwxr-xr-x 2 root wheel 1893064 Mar 26 20:06 git-upload-pack*
-rwxr-xr-x 1 root wheel 333121 Mar 26 20:06 gitk*
Any ideas what might be going wrong?
Thanks
-------------- Edit ------------------- I have the following line in the ".bashrc" of my remote system:
export PATH=$LOCAL/git-1.8/bin/:$PATH
This is the output on the remote machine:
$ls $LOCAL/git-1.8/bin
git git-cvsserver gitk git-receive-pack git-shell git-upload-archive git-upload-pack
And this is the output when I do "ssh user@remote env" from my machine to the remote machine:
[pradeep@laptop ~]$ssh k00603@k.rics.riken.jp env
SHELL=/bin/bash
SSH_CLIENT=153.133.52.171 52379 22
USER=k00603
MAIL=/var/mail/k00603
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/openssh/bin
PWD=/volume2/home/hp120242/k00603
SHLVL=1
HOME=/home/hp120242/k00603
LOGNAME=k00603
SSH_CONNECTION=153.133.52.171 52379 10.7.160.4 22
LC_CTYPE=en_US.UTF-8
_=/bin/env
The git path is missing in the bash.
Edit: The following is the ".bash_profile" in the home directory of my remote system:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:$LOCAL/git-1.8/bin
export PATH
When you ssh into a box and get a prompt, you're actually going through a slight different process than when running a command. Shells have rules about what configuration gets sourced based on whether it's a login shell and/or if it's an interactive session. Try running:
ssh user@host env
This will print your environment as seen by a non-interactive login session. My guess is that /usr/local/git/bin
is not on the path in this scenario. You can work around this by using the --receive-pack
option for git push
:
git push --receive-pack=/path/to/git-receive-pack
/path/to/git-receive-pack
is the path on the remote machine. It tells git where to find the other end when ssh'ing into the remote.
The best answer is to fix your shell configuration, but that can be tricky depending on the shell. I mainly use ZSH, and I fix this by setting up a ~/.zshenv
, which gets sourced by ZSH in a non-interactive shell. I think things tend to be less clear with bash. You may have to edit your ~/.bashrc
and/or your ~/.bash_profile
.
Assuming you have a vanilla Linux installation on the remote end (which is probably the case), and that it's running the bash shell, the easiest fix is to change your .bashrc
. Edit ~/.bashrc
, and add:
export PATH=/path/to/your/installed/git/bin:$PATH
Where /path/to/your/installed/git/bin
is where you installed git in your home directory. I tend to put local installs in ~/.local/bin
, so mine would look like:
export PATH=$HOME/.local/bin:$PATH
Your's may simply be:
export PATH=$HOME/bin:$PATH
You don't say the location, so I can't give you the correct formulation.
On most systems, .bashrc
is sourced even when a command is provided to ssh. After you make this change, try running ssh user@host env
again. You should see your the location of the bin folder holding the git binary in the path variable. You should then be able to do something like ssh user@host git --version
and see something like:
git version 1.8.2
If you see an error, then you likely didn't type the path correctly, or .bashrc isn't being picked up when you ssh into the machine.
Sample .profile
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
Automatically using --receive-pack
Assuming your remote is named origin
, you can do this:
git config --local remote.origin.receivepack \
/path/to/git-receive-pack/on/the/remote
You may need to fix upload pack as well:
git config --local remote.origin.uploadpack \
/path/to/git-upload-pack/on/the/remote
这篇关于git推送错误git-receive-pack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!