2013-02-21 107 views
0

我有一個post-commit鉤子。每次我提交回購時,我都想計算提交編號。我寫道:在鉤子post-commit中執行git命令

#!/bin/sh 
commit_number=$(git shortlog | grep -E '^[ ]+\w+' | wc -l) 
echo "$commit_number" 

每一個新的提交,終端打印0 ...我不知道爲什麼。如果我在我的終端內提交後啓動此命令,我有正確的計數。

回答

0

試着這樣做:

cd .. 
commit_number=$(env -i git shortlog | grep -E '^[ ]+\w+' | wc -l) 
echo "$commit_number" 
+0

THX!我用git rev-list做了它。爲什麼shortlog不一樣? – Pete 2013-02-21 17:40:09