b2977053
3/27/2020 - 9:42 AM

Git Log 格式化顯示

git log --pretty=format:'%Cred%h%Creset %ad |%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset [%Cgreen%an%Creset]' --abbrev-commit --date=short

Commit Formatting

--graph
    text-based graphical representation
--abbrev-commit
    只顯示部分訊息
--date=short
    shows only the date, but not the time, in YYYY-MM-DD format.

--date
    --date=relative 
        5 weeks ago
    --date=raw
        1582545807 +0800
    --date=unix
        1582545807
    --date=iso or iso8601
        2020-02-24 20:03:27 +0800
    --date=human
        Mon Feb 24 20:03
    --date=rfc or rfc2822
        Mon, 24 Feb 2020 20:03:27 +0800
    --date=format:...
        --date=format:'%Y/%m/%d %H:%M:%S'
            2020/02/24 20:03:27
        --date=format:%c
            02/24/20 20:03:27

PRETTY FORMATS

%Cred 改成紅色

%h 縮寫哈希值

%Creset 重製顏色(紅色結束)

%ad date

%C(yellow) 改成黃色

%d (顯示分支)

%Creset

%s 標題

%Cgreen(%cr)%Creset 相對提交日期

[%Cgreen%an%Creset] 使用者名稱

自訂格式

  1. git log --pretty='format:%n%C(auto)%h%n%s%n%ad%n%n--- --- ----' --date=format:'%Y/%m/%d %H:%M:%S' -5