2015-01-10 48 views
1

我有一個別名,我想與代碼配合使用,不知道如何做,以便在運行別名時可以添加後。這可能嗎?例如,這裏是我想別名:在日期之後更改的Git別名日誌

alias gmaat = 'git log --pretty=format:"[%h] %an %ad %s" --date=short --numstat --after=YYYY-MM-DD' 

所以我需要做的是,當我運行gmaat別名,我要麼會被提示添加--AFTER日期或我將運行

gmaat YYYY-MM-DD // filling in the date 

如果這是可能的,我提前感謝可以給予的幫助。

編輯

我嘗試的第一個答案下方加入這樣的:

alias gmaat='!f() { git log --pretty=format:"[%h] %an %ad %s" --date=short --numstat --after=$1 }; f' 

當我運行這一點,別名後添加日期我得到這個錯誤:

fatal: ambiguous argument '2014-11-01': unknown revision or path not in the working tree. 
Use '--' to separate paths from revisions, like this: 
'git <command> [<revision>...] -- [<file>...]' 
+0

我只是修復並測試了答案的第一部分:git別名的作品。 – VonC

回答

0

您可以使用positional parameter

git config alias.gmaat '!f() { git log --pretty=format:"[%h] %an %ad %s" --date=short --numstat --after=$1; }; f' 

注意 ';' 的{ xxx; }

這樣裏面,你可以通過YYYY-MM-DD作爲參數

git gmaat YYYY-MM-DD // filling in the date 

不使用git config alias,那麼你就需要to define in your ~/.bashrc_profile a function

gmaatf() { git log --pretty=format:"[%h] %an %ad %s" --date=short --numstat --after=$1 } 

然後:

alias gmaat=gmaatf 
+0

非常感謝。使用該功能完美工作。 – pertrai1