5

我有一个这样的 gitconfig:

[alias]
l = "!source ~/.githelpers && pretty_git_log"

当我运行它时,我得到了这个:

[desktop] git l
source ~/.githelpers && pretty_git_log: 1: source: not found
error: cannot run source ~/.githelpers && pretty_git_log: No such file or directory
fatal: While expanding alias 'l': 'source ~/.githelpers && pretty_git_log': No such file or directory

当我添加任何其他 shell 内置函数进行测试时,它们运行良好:

[alias]
l = "!echo running from the builtin"

[desktop] git l
running from the builtin

知道为什么无法从 git 中找到源命令吗?我正在运行 zsh,但更改为 bash 似乎没有什么不同:

[desktop] bash
[desktop] git l
source ~/.githelpers && pretty_git_log: 1: source: not found
error: cannot run source ~/.githelpers && pretty_git_log: No such file or directory
fatal: While expanding alias 'l': 'source ~/.githelpers && pretty_git_log': No such file or directory
4

1 回答 1

6

失败来自于!<command>构造试图以该名称查找要运行的程序这一事实。有一个/bin/echo程序(它与你的 shell 内置echo的不同,但那是另一回事),但没有一个/bin/source/usr/bin或任何其他地方)。从本质source上讲,它不能是一个单独的程序。

试试这个:

[alias]
l = "!sh -c 'source ~/.githelpers && pretty_git_log'"

根据需要更改shbash(或其他)。

于 2012-09-19T16:47:52.463 回答