[英]Colors and authors in git log on Windows?
使用 64 位 Windows 10 專業版,我發現了一個很好的命令來列出 Git 歷史記錄,將HEAD
、分支和標簽顯示為突出的顏色。 好的!
git log --oneline --decorate --graph --all
但我沒有看到任何日期或作者! 所以我找到了另一個不錯的命令:
git log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
也很不錯——現在我可以看到日期和作者了。 但是所有漂亮的顏色都消失了(除了圖表)。 HEAD
、分支和標簽都與日志的其余部分顏色相同,因此很難將它們挑出來。
如何在保留日期和作者的同時恢復提交指針的顏色?
這應該可以滿足您的需求:
git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
添加git log --decorate --graph
,它將顯示分支,標簽等。
--decorate
[= short | full | no]打印顯示的所有提交的引用名稱。 如果指定了short,則不會打印ref名稱的前綴refs / heads /,refs / tags /和refs / remotes /。 如果指定了full,則將打印完整的引用名稱(包括前綴)。 默認選項是short
--graph
在輸出的左側繪制提交歷史記錄的基於文本的圖形表示。 這可能會導致在兩次提交之間打印額外的行,以便正確繪制圖形歷史記錄
For windows
format:<string>
格式:format允許您指定要顯示的信息。 它的工作方式類似於printf格式,但值得注意的例外是您使用%n而不是\\ n換行。
例如,格式:
The author of %h was %an, %ar%nThe title was >>%s<<%n
將顯示如下內容:
The author of fe6e0ee was Junio C Hamano, 23 hours ago
The title was >>t4119: test autocomputing -p<n> for traditional diff input.<<
您可以使用日志格式標志
# print out the git log
git log
# print out the branches split and merge points
--graph
# use the --pretty=format:... to choose which data to extract from the log
# (commit) entry and print it out.
# Set colors with the %C<color> & %Creset for resetting back to the default color
The placeholders are
:
%C(…):
顏色規范,如color.branch。*配置選項中所述; 添加auto時,只有在啟用日志輸出的顏色(通過color.diff,color.ui或--color並在要連接到終端時遵守前者的自動設置)的情況下,開始時才會發出顏色。 單獨使用auto(即%C(auto))將在下一個占位符上啟用自動着色,直到再次切換顏色為止。
%C(…):
顏色規范,如color.branch。*配置選項中所述; 添加auto時,只有在啟用日志輸出的顏色(通過color.diff,color.ui或--color並在要連接到終端時遵守前者的自動設置)的情況下,開始時才會發出顏色。 單獨使用auto(即%C(auto))將在下一個占位符上啟用自動着色,直到再次切換顏色為止。
%Cblue:
將顏色切換為藍色
%Cgreen:
將顏色切換為綠色
%Cred:
將顏色切換為紅色
%Creset:
重置顏色
%D:
引用名稱不帶“(”,“)”換行。
%G?:
顯示“ G”以獲得良好的簽名,
“ B”代表錯誤簽名,
“ U”代表良好且不受信任的簽名,並且
“ N”,無簽名
%GG:
來自GPG的原始驗證消息,用於已簽名的提交
%GK:
顯示用於簽署已簽名提交的密鑰
%GS:
顯示簽名提交的簽名者的名字
%H:
提交哈希
%N:
提交筆記
%P:
父哈希
%T:
樹哈希
%aD:
作者日期,RFC2822樣式
%aE:
作者電子郵件(使用.mailmap,請參閱git-shortlog(1)或git-blame(1))
%aI:
作者日期,嚴格的ISO 8601格式
%aN:
作者姓名(使用.mailmap,請參閱git-shortlog(1)或git-blame(1))
%ad:
作者日期(格式方面--date =選項)
%ae:
作者電子郵件
%ai:
作者日期,類似於ISO 8601的格式
%an:
作者姓名
%ar:
作者日期,相對
%at:
作者日期,UNIX時間戳
%b:
身體
%cD:
提交者日期,RFC2822樣式
%cE:
提交者電子郵件(使用.mailmap,請參閱git-shortlog(1)或git-blame(1))
%cI:
提交者日期,嚴格的ISO 8601格式
%cN:
提交者名稱(使用.mailmap,請參閱git-shortlog(1)或git-blame(1))
%cd:
提交者日期(格式方面--date =選項)
%ce:
提交者電子郵件
%ci:
提交者日期,類似於ISO 8601的格式
%cn:
提交者名稱
%cr:
提交者日期(相對)
%ct:
提交者日期,UNIX時間戳
%d:
引用名稱,例如git-log(1)的--decorate選項
%e:
編碼
%f:
清理的主題行,適用於文件名
%gD:
引用日志選擇器,例如refs / stash @ {1}
%gE:
reflog身份電子郵件(尊重.mailmap,請參閱git-shortlog(1)或git-blame(1))
%gN:
引用日志標識名稱(使用.mailmap,請參閱git-shortlog(1)或git-blame(1))
%gd:
縮短的引用日志選擇器,例如stash @ {1}
%ge:
reflog身份電子郵件
%gn:
reflog身份名稱
%gs:
主題
%h:
縮寫提交哈希
%m:
左,右或邊界標記
%n:
換行符
%p:
縮寫的父哈希
%s:
主題
%t:
縮寫樹哈希
%w([<w>[,<i1>[,<i2>]]]):
切換換行,就像git-shortlog(1)的-w選項一樣。
%x00:
從十六進制代碼打印字節
On unix
.githelpers
操作系統,則可以使用此.githelpers
Output of the .githelprs script:
您可以使用%C(auto)
和%C(reset)
包裝格式字符串以%C(auto)
為輸出着色,如下所示:
%C(auto)<insert your formatting here>%C(reset)
因此,使用您提供的格式:
git log --pretty=format:"%C(auto)%h %ad | %s%d [%an]%C(reset)" --graph --date=short
它將使用 git 的默認顏色來處理分支(遠程為紅色,本地為綠色,HEAD 為青色等)和提交參考。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.