結果的sehe的版本:SEH的
# git for-each-ref --format="%(refname) %(objectname) %(subject)" \
| grep /tags/ | sed 's#^refs/tags/##'
initial a9dcc1f24cacde535523bddc22f4c69467428550 initial commit
v0.1.1-alpha b784145a9a71478337f5ceae30aaac4e1b955ee5 initial version. big chance to work. not quite tested
v0.1.2-alpha 193993aabb0c3634ebea0405ecd420e99c609422 it is still alpha
v0.1.3-alpha 415fb8f25982233b1b1211d8500e923e40ce64fd works better. not tested in details.
結果E公司的短輸出(如默認輸出的Git分支-v)版本:
# git for-each-ref --format="%(refname) %(objectname:short) %(subject)" \
| grep /tags/ | sed 's#^refs/tags/##'
initial a9dcc1f initial commit
v0.1.1-alpha b784145 initial version. big chance to work. not quite tested
v0.1.2-alpha 193993a it is still alpha
v0.1.3-alpha 415fb8f works better. not tested in details.
我的版本的結果:
initial a9dcc1f initial commit
v0.1.1-alpha a9dcc1f initial version. big chance to work. not quite tested
v0.1.2-alpha 8dd326d it is still alpha
v0.1.3-alpha 54d7ccd works better. not tested in details.
這裏初始是輕量級的標籤
差異:
- (最重要)第一列自動填充到最大標籤l ength - 更具可讀性
- SHA1承諾標籤指向即使它不是輕量級標籤。這樣你可以很容易地看到最初的指向與v0.1.1-alpha相同的提交。這種行爲很容易做到可選。
我的腳本太長。我只會發布git調用函數(bash腳本)。大部分是取自混帳的for-each-REF手冊頁:
function gitTags(){
arg="$1"
REF=${arg:-"*"}
fmt='
r=%(refname)
t=%(*objecttype)
T=${r#refs/tags/}
o=%(*objectname:short)
s=%(subject)
kind="T"
if [ "$t" = "" ] ; then
# could be a lightweight tag
t=%(objecttype)
kind="L"
o=%(objectname:short)
fi
len=${#T}
if [ "$len" -gt ${len1:-0} ]; then
len1=$len
fi
echo -e "$T\t$o\t$s"
'
eval=`git for-each-ref --shell --format="$fmt" \
--sort='*objecttype' --sort=taggerdate "refs/tags/$REF"`
out=`eval "$eval"'echo $len1;'`
local len1=`echo "$out"|tail -n 1`
echo "$out"|head -n -1 \
|awk 'BEGIN{FS="\t"}{printf("%-'$len1's %s %s\n", $1, $2, $3)}'
}
用法:
#show all tags:
gitTags
#show all tags starting with v (v1.0)
gitTags v*
在['git-for-each-ref'手冊頁中有一個*瘋狂*詳細的例子(http://www.kernel.org/pub/software/scm/git/docs/git-for- each-ref.html) - 大幅減少它會做你想要的。當我有機會時,我會爲你寫點東西。 – Cascabel 2011-04-03 14:22:41
我會檢查它。謝謝 – NickSoft 2011-04-03 14:41:05