[Git] 列出所有的標籤 (tag) 與標記日期

[Git] 列出所有的標籤 (tag) 與標記日期

以前在用 Perforce 的時候,

蠻常會需要把所有的標籤 (Label) 列出來,

依照 Perforce GUI 上顯示的日期,來過濾某個問題可能出現在哪一個版本上。

 

現在換用 Git 了,但 git tag 平常只會顯示標籤名稱,看不到日期:

testuser@localhost ~ $ git tag

TestProj_1.0.1001
TestProj_1.0.1002
TestProj_1.0.1003
TestProj_1.0.1003_DEV1
TestProj_1.0.1004
TestProj_1.0.1005
TestProj_1.0.1006
TestProj_1.0.1007

 

當然你可以用 git show <tag name> 的方式,來查看一個標籤的建立日期,

不過那樣實在很麻煩,沒辦法很快的說,

在某天進的某段 code,是不是有在某個版本裡面…

testuser@localhost ~ $ git show TestProj_1.0.1001

commit 1d668365caffa5f6c9d8fab72f038d1aa53ead74 (tag: TestProj_1.0.1001)
Merge: a31473f6 bb58e29c
Author: Jenkins Continuous Build server <jenkins@localhost.localdomain>
Date:   Tue Jan 7 16:05:03 2020 +0800

    Merge branch 'dev'

 

查了一下,得用 git for-each-ref 這個指令來達到目的。

下面是我調整過指令,好讓標籤部分可以保留一定寬度來對齊,

同時讓日期的部分用 iso 方式顯示, 方便比較:

testuser@localhost ~ $ git for-each-ref --format="%(align:25)%(refname:short)%(end) | %(creatordate:iso)" refs/tags/*

TestProj_1.0.1001         | 2020-01-05 10:05:00 +0800
TestProj_1.0.1002         | 2020-01-06 08:05:00 +0800
TestProj_1.0.1003         | 2020-01-07 16:05:00 +0800
TestProj_1.0.1003_DEV1    | 2020-01-07 16:05:00 +0800
TestProj_1.0.1004         | 2020-01-08 02:10:00 +0800
TestProj_1.0.1005         | 2020-01-09 09:23:00 +0800
TestProj_1.0.1006         | 2020-01-09 10:05:00 +0800
TestProj_1.0.1007         | 2020-01-10 17:54:00 +0800

 

當然每次都要打這麼長的話,實在太累了。

因此我是設定一個 alias 來執行囉:

alias gt='git for-each-ref --format="%(align:25)%(refname:short)%(end) | %(creatordate:iso)" refs/tags/*'

 

參考資料:

Get the time and date of git tags – Stack Overflow
Git – git-for-each-ref Documentation
Git – git-rev-list Documentation

(本頁面已被瀏覽過 658 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料