2013-09-30 61 views
1

我已經安裝了一個自定義的git的別名來做出漂亮的git的日誌像這樣在我~/.gitconfig來源的git的別名失敗

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

~/.githelpers文件包含以下內容:

#!/bin/bash 

HASH="%C(yellow)%h%C(reset)" 
RELATIVE_TIME="%C(green)%ar%C(reset)" 
AUTHOR="%C(bold blue)%an%C(reset)" 
REFS="%C(red)%d%C(reset)" 
SUBJECT="%s" 

FORMAT="$HASH{$RELATIVE_TIME{$AUTHOR{$REFS $SUBJECT" 

function git_pretty_log() { 
    git log --graph --pretty="tformat:$FORMAT" $* | 
    column -t -s '{' | 
    less -FXRS 
} 

但是當我做git l在任何回購我有我得到:

$ git l 
source ~/.githelpers && git_pretty_log: 1: source ~/.githelpers && git_pretty_log: source: not found 
fatal: While expanding alias 'l': 'source ~/.githelpers && git_pretty_log': Aucun fichier ou dossier de ce type 

任何想法?

+0

什麼是「Aucun fichier歐檔案德CE型」是什麼意思? – poke

+0

@poke:沒有此類型的文件或文件夾。 – Ryan

+0

如果你用'echo hello'替換'git_pretty_log',它會起作用嗎? – Ryan

回答

3

錯誤似乎是source不是一個外部二進制文件,而是一個bash內建的。

$ git config alias.foo '!source .gitfoo' 
$ git foo 
source .gitfoo: 1: source .gitfoo: source: not found 

結束語這一切都與一個bash -c解決了這個問題。

$ git config alias.foo '!'"bash -c 'source .gitfoo && gitfoobar'" 
$ echo 'function gitfoobar() { echo foo bar; }' >.gitfoo 
$ git foo 
foo bar 

對於您的情況:

git config --global alias.l '!'"bash -c 'source ~/.githelpers && git_pretty_log'" 
+0

(而且它被引用,但是,是的,這是正確的修復':)') – Ryan

+0

完美,謝謝! – manu

-1

刪除引號;它應該是:

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

否則,您試圖運行一個不存在的長命令,就像錯誤消息告訴您的那樣。

+0

我在發帖前試過這個。這似乎並不實質... – manu