我在不同的网络上有两个git存储库.我一直在他们两个之间进行沟通没有问题,但出于某种原因,今天当我做"git push"时,我收到以下错误:
----------------------------------------------
bash: git-receive-pack: command not found
fatal: The remote end hung up unexpectedly
----------------------------------------------
Run Code Online (Sandbox Code Playgroud)
我用Google搜索并确保"/ usr/local/bin"在我的"$ PATH"中.这是我的git的bin目录的输出:
[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*
Run Code Online (Sandbox Code Playgroud)
什么想法可能会出错?
谢谢
--------------编辑-------------------我的远程系统的".bashrc"中有以下行:
export PATH=$LOCAL/git-1.8/bin/:$PATH
Run Code Online (Sandbox Code Playgroud)
这是远程机器上的输出:
$ls $LOCAL/git-1.8/bin
git git-cvsserver gitk git-receive-pack git-shell git-upload-archive git-upload-pack
Run Code Online (Sandbox Code Playgroud)
当我从我的机器"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/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
Run Code Online (Sandbox Code Playgroud)
bash中缺少git路径.
编辑:以下是我的远程系统的主目录中的".bash_profile":
# .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
Run Code Online (Sandbox Code Playgroud)
当你进入一个框并获得提示时,你实际上要经历一个与运行命令时稍微不同的过程.Shell根据是否是登录shell和/或它是否是交互式会话,有关于配置源的规则.试试跑步:
ssh user@host env
Run Code Online (Sandbox Code Playgroud)
这将打印您的环境,如非交互式登录会话所示.我的猜测是/usr/local/git/bin在这种情况下不在路径上.您可以使用以下--receive-pack选项解决此问题git push:
git push --receive-pack=/path/to/git-receive-pack
Run Code Online (Sandbox Code Playgroud)
/path/to/git-receive-pack是远程计算机上的路径.它告诉git在ssh进入遥控器时在哪里找到另一端.
最好的答案是修复shell配置,但根据shell的不同,这可能很棘手.我主要使用ZSH,我通过设置一个来解决这个问题~/.zshenv,它由ZSH在非交互式shell中提供.我觉得用bash来说事情往往不太清楚.您可能需要编辑您的~/.bashrc和/或您的~/.bash_profile.
假设您在远程端安装了一个vanilla Linux(可能就是这种情况),并且它正在运行bash shell,最简单的解决方法是更改您的.bashrc.编辑~/.bashrc并添加:
export PATH=/path/to/your/installed/git/bin:$PATH
Run Code Online (Sandbox Code Playgroud)
哪里/path/to/your/installed/git/bin是你在你的home目录中安装的git.我倾向于将本地安装~/.local/bin,因此我的看起来像:
export PATH=$HOME/.local/bin:$PATH
Run Code Online (Sandbox Code Playgroud)
你可能只是:
export PATH=$HOME/bin:$PATH
Run Code Online (Sandbox Code Playgroud)
你没有说位置,所以我不能给你正确的配方.
在大多数系统上,.bashrc即使向ssh提供命令也会获取.进行此更改后,请尝试ssh user@host env再次运行.您应该在路径变量中看到包含git二进制文件的bin文件夹的位置.然后你应该能够做类似的事情ssh user@host git --version并看到类似的东西:
git version 1.8.2
Run Code Online (Sandbox Code Playgroud)
如果您看到错误,那么您可能没有正确键入路径,或者当您进入计算机时未获取.bashrc.
示例.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
Run Code Online (Sandbox Code Playgroud)
自动使用 --receive-pack
假设您的遥控器已命名origin,您可以这样做:
git config --local remote.origin.receivepack \
/path/to/git-receive-pack/on/the/remote
Run Code Online (Sandbox Code Playgroud)
您可能还需要修复上传包:
git config --local remote.origin.uploadpack \
/path/to/git-upload-pack/on/the/remote
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7461 次 |
| 最近记录: |