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

テストする他のシェルビルトインを追加すると、正常に実行されます。

[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(シェルに組み込まれているものとは異なりますechoが、話は異なります)、/bin/source(または/usr/bin他の場所)はありません。何をするのかという性質上source、それは別個のプログラムになることはできません。

代わりにこれを試してください:

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

必要に応じて(または何でも)に変更shします。bash

于 2012-09-19T16:47:52.463 に答える