【问题标题】:git-upload-pack: command not foundgit-upload-pack:找不到命令
【发布时间】:2012-06-23 02:46:14
【问题描述】:

我已经阅读了这个答案大约八五遍,但有些东西我没有正确理解:

git-upload-pack: command not found, how to fix this correctly

当我尝试在我的服务器上克隆存储库时,我得到以下信息:

bash: git-upload-pack: command not found

但是当我通过给克隆提供-u /usr/local/bin/git-upload-pack 选项进行克隆时,一切正常。

我想这是有道理的,因为这是 git-upload-pack 在我的服务器上的位置。

最佳答案表明我在服务器上的 .bashrc 文件需要更新以反映这一点,因为 ssh you@remotemachine echo \$PATH 的结果不返回 /usr/local/bin。 (它返回/usr/bin:/bin:/usr/sbin:/sbin)。

但是当我查看我的 .bashrc 文件时,它包含:

export PATH=/usr/local/bin:$PATH

所以现在我很困惑。

我需要做些什么来避免每次都使用-u /usr/local/bin/git-upload-pack 选项?为什么ssh you@remotemachine echo \$PATH 不返回/usr/local/bin?这与登录和非登录 shell 有关吗?

请帮忙!提前致谢。

【问题讨论】:

标签: git bash shell command-line


【解决方案1】:

是的,它与登录和非登录 shell 有关。 .bashrc 文件仅在非登录 shell 中加载。您可以使用.bash_profile 登录shell。只需在.bash_profile 文件中对您的PATH 添加相同的修改即可。

export PATH=/usr/local/bin:$PATH

你可以找到this is an interesting article on the difference between .bashrc and .bash_profile, and login and non-login shells.

【讨论】:

  • 谢谢!完全有道理——但似乎对我不起作用。我的.bash_profile.bashrc 都包含代码export PATH=/usr/local/bin:$PATH,但这并不能解决问题。 ssh you@remotemachine echo \$PATH 仍然返回 /usr/bin:/bin:/usr/sbin:/sbin。可能的原因? (猜测。) 1. 我在 Media Temple 服务器上,并且有一个 .bash_mt_profile 文件。 (但我添加了export PATH=/usr/local/bin:$PATH 以取得好的效果,但它似乎不起作用。) 2. 我以root 身份登录。 3.我没有使用bash(但是当我登录时,它说我可以编辑我的.bash_profile以删除系统消息。
  • @Chris:出于兴趣,您的.bash_profile/.bashrc 文件是否将权限设置为 644,归正确的用户所有,并且没有设置可执行位?该文件是源文件,而不是执行文件,但必须由尝试源文件的用户拥有,并且必须具有 644(或更高)权限。如果在检查这些后仍然失败,您可以随时尝试将 PATH 更改添加到 /etc/profile/etc/profile.d/*(取决于您的发行版)。
  • 再次感谢。是的,烫发是644。无论如何我都重置了它们。它没有用。向/etc/profile.d/ 添加了一个名为 git.sh 的文件,代码为export PATH=/usr/local/bin:$PATH(这是正确的做法吗?),但这也没有奏效。我只能假设我没有做过明显的事情。
  • 是的,这是正确的代码。我唯一能想到的可能是git.sh 文件不可执行,试试chmod +x 看看是否有区别?除此之外,听起来 MT 服务器可能在某个较低级别对 PATH 变量进行硬编码?
  • 我遇到了类似的问题,我没有 root 访问权限。所以对我来说,这个答案比公认的答案更优越。
【解决方案2】:

这与这个问题有关:

https://serverfault.com/questions/130834/svnssh-getting-bash-to-load-my-path-over-ssh

在不进入交互模式的情况下发送命令时,默认情况下 Ssh 不会加载您的环境。

好的解决方案是带有 .ssh/environment 文件的解决方案:

在 /etc/ssh/sshd_config 添加:

PermitUserEnvironment yes

然后只需创建 .ssh/ 目录并将环境转储到 .ssh/enviroment :

cd ~/
mkdir .ssh
env > .ssh/environment

重启 SSH

/etc/init.d/sshd restart

现在,当您从本地计算机执行此操作时:

ssh you@server.com  "which git-upload-pack"

你会得到

/usr/local/bin/git-upload-pack

并且 git clone s'd 工作。

【讨论】:

  • 我试图在我的 Mac 上使用 ssh 访问一个 git repo。我必须编辑 /etc/ssh/sshd_config 并添加“PermitUserEnvironment yes”,然后通过系统首选项->共享->删除登录重新启动 sshd。我不必创建 .ssh/environment 文件
  • 看起来像是重启命令中的错字。不应该是:/etc/init.d/ssh restart 吗?
【解决方案3】:

我收到以下错误: git-credential-osxkeychain died of signal 11 当我在做 git pull 时,我会得到 fatal: @987654321@ not found: did you run git update-server-info on the server?

我猜这与我之前在钥匙串中无效的 github 凭据有关。

  • 使用命令空间打开钥匙串访问工具
  • 在钥匙串访问工具中搜索了github
  • 删除所有与 github 相关的条目(因为我不再需要它)
  • 再次遵循设置 git 密码缓存部分setup git
  • 成功了

如果以上任何一个答案都没有帮助。

【讨论】:

    【解决方案4】:

    我对这个问题的解决方案

    1. 检查远程机器上 git-upload-pack 的路径:

      ssh yourname@IP-addressORdomain 'which git-upload-pack'
      

    如果它给出了路径 - 复制它(不带 git-upload-pack 和尾部斜杠。例如:/usr/bin/home/yourname/bin/whatever/gituploadpack/path 等)。

    1. 在登录 shell 期间检查远程计算机上的 PATH:

      ssh yourname@IP-addressORdomain 'echo $PATH'
      

    没有这样的路径(/whatever/gituploadpack/path),不是吗?好!

    1. 登录到您的远程计算机:

      ssh yourname@IP-addressORdomain
      
    2. 打开 .bashrc_profile:

      nano /home/yourname/.bashrc_profile
      
    3. 找到这些行(如果有):

      if [ -f ~/.bashrc ]; then
           ~/.bashrc
      fi
      

    ...并将它们更改为:

        if [ -f ~/.bashrc ]; then
            source ~/.bashrc
        fi
    
    1. 打开.bashrc:

      nano /home/yourname/.bashrc
      
    2. 添加这 4 行:

      if [ -d "/whatever/gituploadpack/path" ] ; then
        PATH="$PATH:/whatever/gituploadpack/path"
      fi
      export PATH
      
    3. 退出远程机器:

      exit
      
    4. 在登录 shell 期间检查远程计算机上的 PATH:

      ssh yourname@IP-addressORdomain 'echo $PATH'
      

    你看到/whatever/gituploadpack/path了吗?恭喜!

    请注意,现在您不仅解决了git-upload-pack 问题,还解决了git-receive-pack/whatever/gituploadpack/path 上的其他可执行文件!

    【讨论】:

      【解决方案5】:

      我通过登录远程机器、Ubuntu 机器并执行sudo apt-get install git 解决了这个问题。不确定这是否矫枉过正,但立即为我解决了问题。

      【讨论】:

      • 起初我以为git-upload-pack只是客户端环境中缺少的依赖,但它并没有丢失。然后这个答案帮助我意识到“找不到命令”错误实际上是指未安装 Git 的 远程环境(在我的情况下,是连接到 LAN 的 Raspberry Pi)。
      猜你喜欢
      • 2012-03-16
      • 2010-09-18
      • 2013-02-25
      • 2011-08-27
      • 2012-05-07
      • 1970-01-01
      • 2019-01-15
      • 1970-01-01
      相关资源
      最近更新 更多