linux git-shell,linux – 使用git-shell的自定义命令

本文描述了在Linux环境中为git-shell创建自定义命令遇到的问题。作者创建了一个名为gituser的用户,设置了/usr/bin/git-shell作为其shell,并在git-shell-commands目录下放入了一个脚本,但无法通过ssh执行该脚本。问题在于所使用的git版本过低,自定义命令在git 1.7.4之后才被引入,且在非交互模式下不支持。升级git版本后,自定义命令可以在交互模式下运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如何为git-shell创建自定义命令?根据documentation:

When -c is given, the program executes non-interactively;

can be one of git receive-pack, git upload-pack, git

upload-archive, cvs server, or a command in COMMAND_DIR. The shell is

started in interactive mode when no arguments are given; in this case,

COMMAND_DIR must exist, and any of the executables in it can be

invoked.

但是,我不确定我是否正确理解这一点.我创建了一个名为gituser的用户,并将/usr/bin/git-shell作为shell.我创建了一个名为git-shell-commands的目录,并在其中放入了一个名为“testy”的脚本,但我无法通过git-shell运行它.

这是我正在尝试从另一台机器:

$ssh gituser@server.com testy

fatal: unrecognized command 'testy'

请注意,git-shell正在运行,并且响应,它无法找到我的自定义命令.

以下是脚本:

:/home/gituser/git-shell-commands# ls -l -a

total 12

drwxr-xr-x 2 gituser gituser 4096 Jan 22 17:35 .

drwxr-xr-x 4 gituser gituser 4096 Jan 22 13:57 ..

-rwxr-xr-x 1 gituser gituser 26 Jan 22 13:58 testy

:/home/gituser/git-shell-commands# ./testy

hello!

:/home/sodigit/git-shell-commands# cat testy

echo "hello!"

我究竟做错了什么?如何使用git-shell运行自定义命令?

解决方法:

事实证明,这个功能已经在git 1.7.4中引入.我正在使用debian squeeze,它包含一个旧版本的git,所以这就是为什么它不起作用.

如果您遇到此问题,请检查您的git版本.

但是,从git 1.7.10开始,自定义命令仅在交互模式下工作,而不在-c中工作.我没有尝试过最新的git,所以这个问题可能与软件版本无关.

标签:git,shell,linux,ssh

来源: https://codeday.me/bug/20190517/1123324.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值