git-upload-pack:在克隆远程 Git 存储库时找不到命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/225291/
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 05:53:49  来源:igfitidea点击:

git-upload-pack: command not found, when cloning remote Git repo

gitversion-controlunixssh

提问by Chris Huang-Leaver

I have been using git to keep two copies of my project in sync, one is my local box, the other the test server. This is an issue which occurs when I log onto our remote development server using ssh;

我一直在使用 git 使我的项目的两个副本保持同步,一个是我的本地机器,另一个是测试服务器。这是当我使用 ssh 登录到我们的远程开发服务器时发生的问题;

git clone [email protected]:/home/chris/myproject
Initialized empty Git repository in /tmp/myproject/.git/
Password:
bash: git-upload-pack: command not found
fatal: The remote end hung up unexpectedly
fetch-pack from '[email protected]:/home/chris/myproject' failed.

(the file-names have been changed to protect the guilty... !)

(文件名已更改以保护有罪者......!)

Both boxes run Solaris 10 AMD. I have done some digging, if I add --upload-pack=$(which git-upload-pack)the command works, (and proves that $PATHcontains the path to 'git-upload-pack' as per the RTFM solution) but this is really annoying, plus 'git push' doesn't work, because I don't think there is a --unpack=option.

两个机器都运行 Solaris 10 AMD。我已经进行了一些挖掘,如果我添加--upload-pack=$(which git-upload-pack)命令有效,(并证明$PATH根据 RTFM 解决方案包含“git-upload-pack”的路径)但这真的很烦人,加上“git push”不起作用,因为我认为没有--unpack=选择。

Incidentally, all the git commands work fine from my local box, it is the same version of the software (1.5.4.2), installed on the same NFS mount at /usr/local/bin.

顺便说一句,所有 git 命令在我的本地机器上都可以正常工作,它是相同版本的软件 (1.5.4.2),安装在/usr/local/bin.

Can anybody help?

有人可以帮忙吗?

采纳答案by Matt Curtis

Make sure git-upload-packis on the path from a non-login shell. (On my machine it's in /usr/bin).

确保git-upload-pack位于非登录 shell 的路径上。(在我的机器上它在/usr/bin)。

To see what your path looks like on the remote machine from a non-login shell, try this:

要从非登录 shell 查看远程计算机上的路径,请尝试以下操作:

ssh you@remotemachine echo $PATH

(That works in Bash, Zsh, and tcsh, and probably other shells too.)

(这适用于 Bash、Zsh 和 tcsh,可能也适用于其他 shell。)

If the path it gives back doesn't include the directory that has git-upload-pack, you need to fix it by setting it in .bashrc(for Bash), .zshenv(for Zsh), .cshrc(for tcsh) or equivalent for your shell.

如果它返回的路径不包含具有 的目录,则git-upload-pack需要通过将其设置为.bashrc(对于 Bash)、.zshenv(对于 Zsh)、.cshrc(对于 tcsh)或 shell 的等效项来修复它。

You will need to make this change on the remote machine.

您需要在远程计算机上进行此更改。

If you're not sure which path you need to add to your remote PATH, you can find it with this command (you need to run this on the remote machine):

如果您不确定需要将哪个路径添加到 remote PATH,您可以使用以下命令找到它(您需要在远程机器上运行它):

which git-upload-pack

which git-upload-pack

On my machine that prints /usr/bin/git-upload-pack. So in this case, /usr/binis the path you need to make sure is in your remote non-login shell PATH.

在我的机器上打印/usr/bin/git-upload-pack. 因此,在这种情况下,/usr/bin您需要确保路径在远程非登录 shell 中PATH

回答by Brian Hawkins

You can also use the "-u" option to specify the path. I find this helpful on machines where my .bashrc doesn't get sourced in non-interactive sessions. For example,

您还可以使用“-u”选项来指定路径。我发现这在我的 .bashrc 不在非交互式会话中获取的机器上很有帮助。例如,

git clone -u /home/you/bin/git-upload-pack you@machine:code

回答by Garrett

Building on Brian's answer, the upload-pack path can be set permanently by running the following commands after cloning, which eliminates the need for --upload-packon subsequent pull/fetch requests. Similarly, setting receive-pack eliminates the need for --receive-packon push requests.

基于Brian 的回答,可以通过在克隆后运行以下命令来永久设置上传包路径,从而无需--upload-pack后续的拉取/提取请求。同样,设置 receive-pack 消除了--receive-pack对推送请求的需要。

git config remote.origin.uploadpack /path/to/git-upload-pack
git config remote.origin.receivepack /path/to/git-receive-pack

These two commands are equivalent to adding the following lines to a repo's .git/config.

这两个命令相当于将以下几行添加到 repo 的.git/config.

[remote "origin"]
    uploadpack = /path/to/git-upload-pack
    receivepack = /path/to/git-receive-pack

Frequent users of clone -umay be interested in the following aliases. myclone should be self-explanatory. myfetch/mypull/mypush can be used on repos whose config hasn't been modified as described above by replacing git pushwith git mypush, and so on.

的频繁用户clone -u可能对以下别名感兴趣。myclone 应该是不言自明的。myfetch / mypull / mypush可以在其回购配置如上述通过更换描述没有被修改被用于git pushgit mypush,等等。

[alias]
    myclone = clone --upload-pack /path/to/git-upload-pack
    myfetch = fetch --upload-pack /path/to/git-upload-pack
    mypull  = pull --upload-pack /path/to/git-upload-pack
    mypush  = push --receive-pack /path/to/git-receive-pack

回答by Andy

I found and used (successfully) this fix:

我发现并使用(成功)此修复程序:

# Fix it with symlinks in /usr/bin
$ cd /usr/bin/
$ sudo ln -s /[path/to/git]/bin/git* .

Thanks to Paul Johnston.

感谢保罗约翰斯顿

回答by tom

Mac OS X and some other Unixes at least have the user path compiled into sshd for security reasons so those of us that install git as /usr/local/git/{bin,lib,...} can run into trouble as the git executables are not in the precompiled path. To override this I prefer to edit my /etc/sshd_config changing:

出于安全原因,Mac OS X 和其他一些 Unix 至少将用户路径编译到 sshd 中,因此我们这些将 git 安装为 /usr/local/git/{bin,lib,...} 的人可能会遇到麻烦,因为 git可执行文件不在预编译路径中。要覆盖它,我更喜欢编辑我的 /etc/sshd_config 更改:

#PermitUserEnvironment no

to

PermitUserEnvironment yes

and then create ~/.ssh/environment files as needed. My git users have the following in their ~/.ssh/environment file:

然后根据需要创建 ~/.ssh/environment 文件。我的 git 用户在他们的 ~/.ssh/environment 文件中有以下内容:

PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin

Note variable expansion does not occur when the ~/.ssh/environment file is read so:

请注意,读取 ~/.ssh/environment 文件时不会发生变量扩展,因此:

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

will not work.

不管用。

回答by tom

For bash, it needs to be put into .bashrc not .bash_profile (.bash_profile is also only for login shells).

对于 bash,它需要放入 .bashrc 而不是 .bash_profile (.bash_profile 也仅用于登录 shell)。

回答by Skeletron

Matt's solution didn't work for me on OS X, but Paul's did.

Matt 的解决方案在 OS X 上对我不起作用,但 Paul 的解决方案对我有用。

The short version from Paul's link is:

保罗链接的简短版本是:

Created /usr/local/bin/ssh_sessionwith the following text:

/usr/local/bin/ssh_session使用以下文本创建:

#!/bin/bash
export SSH_SESSION=1
if [ -z "$SSH_ORIGINAL_COMMAND" ] ; then
    export SSH_LOGIN=1
    exec login -fp "$USER"
else
    export SSH_LOGIN=
    [ -r /etc/profile ] && source /etc/profile
    [ -r ~/.profile ] && source ~/.profile
    eval exec "$SSH_ORIGINAL_COMMAND"
fi

Execute:

执行:

chmod +x /usr/local/bin/ssh_session

chmod +x /usr/local/bin/ssh_session

Add the following to /etc/sshd_config:

将以下内容添加到/etc/sshd_config

ForceCommand /usr/local/bin/ssh_session

ForceCommand /usr/local/bin/ssh_session

回答by Ric Tokyo

I got these errors with the MsysGit version.

我在 MsysGit 版本中遇到了这些错误。

After following all advice I could find here and elsewhere, I ended up:

在遵循我可以在这里和其他地方找到的所有建议之后,我最终得到了:

installing the Cygwin version of Git

安装 Cygwin 版本的 Git

on the server (Win XP with Cygwin SSHD), this finally fixed it.

在服务器上(使用 Cygwin SSHD 的 Win XP),这终于修复了它。

I still use the MsysGit version client side

我仍然使用 MsysGit 版本客户端

..in fact, its the only way it works for me, since I get POSIX errors with the Cygwin Git pull from that same sshd server

..事实上,这是它对我有用的唯一方法,因为我从同一个 sshd 服务器中提取 Cygwin Git 时出现 POSIX 错误

I suspect some work is still needed this side of Git use.. (ssh+ease of pull/push in Windows)

我怀疑在 Git 使用的这一方面仍然需要一些工作..(ssh + 在 Windows 中易于拉/推)

回答by Stefan Lundstr?m

Like Johan pointed out many times its .bashrc that's needed:

就像 Johan 多次指出它需要的 .bashrc 一样:

ln -s .bash_profile .bashrc

ln -s .bash_profile .bashrc

回答by Dennis

You must add the

您必须添加

export PATH=/opt/git/bin:$PATH

before this line in the .bashrc:

在 .bashrc 中的这一行之前:

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

Otherwise all export statements will not be executed (see here).

否则将不会执行所有导出语句(请参阅此处)。