我想調整git reflog
的默認輸出,但我首先需要格式字符串來重現默認輸出。具體地講,我無法用不同refnames的着色:`git reflog`默認輸出的格式字符串是什麼?
有人更見地使用Git能幫助我嗎?
我想調整git reflog
的默認輸出,但我首先需要格式字符串來重現默認輸出。具體地講,我無法用不同refnames的着色:`git reflog`默認輸出的格式字符串是什麼?
有人更見地使用Git能幫助我嗎?
每the git reflog
documentation:
git reflog show
是git log -g --abbrev-commit --pretty=oneline
一個別名,然後應該送你到the git log
documentation,它說一點關於--pretty=oneline
,卻隱藏着下-g
又名--walk-reflogs
說明一個重要的位:
With
--pretty
格式不是oneline
(出於顯而易見的原因),這會導致輸出從reflog中獲取兩行額外的信息。在輸出中的引用日誌指示符可被示爲[email protected]{Nth}
(其中Nth
是在引用日誌的逆時間指數)或作爲[email protected]{timestamp}
(與時間戳該條目),這取決於幾個規則:
如果起始點指定爲
[email protected]{Nth}
,顯示索引格式。如果起始點被指定爲
[email protected]{now}
,請顯示時間戳格式。如果兩者均未使用,但在命令行中給出,請以所請求的格式顯示時間戳。
否則,顯示索引格式。
在
--pretty=oneline
之下,提交消息在同一行上以該信息爲前綴。該選項不能與--reverse
結合使用。另請參閱git-reflog(1)。
的「起點」這一暗示是你與你的git log -g
命令鳴哨引用日誌條目。如果你沒有給一個,git log
默認爲HEAD
,不具有任何格式,所以這屬於規則3或4:
git log --pretty=oneline -g [email protected]{now}
明確使用規則2,但:
git log --pretty=oneline -g [email protected]{0}
例如明確使用規則1。
小,它說,或者不說,大約--pretty=oneline
是,它是大致相當於這取決於您是否使用--abbrev-commit
%H %gd %s
或%h %gd %s
。但是如果你在配置文件中設置了log.decorate=auto
和標準輸出將進入一個交互設備,那麼你也可以從%d
中插入。
「互動裝置」 是任何被指定爲 「TTY」 C庫isatty
功能。
的默認格式字符串reflog
是這樣的:
git reflog --format='%C(auto)%h %gd: %gs (%s)'
顏色可以與%C
進行修改。例如,爲了最初的黃色變爲品紅色:
git reflog --format='%C(magenta)%h%C(reset) %gd: %gs (%s)'
注意%C(reset)
是絕對必要的,因爲着色是使用ANSI escape sequences
和它們必須被正確端接實現。如果您是古怪的,請查看color.h
的git
代碼,查看這些序列的外觀。
對於所有可能的格式字符串看到format:<string>
在man git-log
:
· format:<string> The format:<string> format allows you to specify which information you want to show. It works a little bit like printf format, with the notable exception that you get a newline with %n instead of \n. E.g, format:"The author of %h was %an, %ar%nThe title was >>%s<<%n" would show something like this: The author of fe6e0ee was Junio C Hamano, 23 hours ago The title was >>t4119: test autocomputing -p<n> for traditional diff input.<< The placeholders are: · %H: commit hash · %h: abbreviated commit hash · %T: tree hash · %t: abbreviated tree hash · %P: parent hashes · %p: abbreviated parent hashes · %an: author name · %aN: author name (respecting .mailmap, see git-shortlog(1) or git-blame(1)) · %ae: author email · %aE: author email (respecting .mailmap, see git-shortlog(1) or git-blame(1)) · %ad: author date (format respects --date= option) · %aD: author date, RFC2822 style · %ar: author date, relative · %at: author date, UNIX timestamp · %ai: author date, ISO 8601-like format · %aI: author date, strict ISO 8601 format · %cn: committer name · %cN: committer name (respecting .mailmap, see git-shortlog(1) or git-blame(1)) · %ce: committer email · %cE: committer email (respecting .mailmap, see git-shortlog(1) or git-blame(1)) · %cd: committer date (format respects --date= option) · %cD: committer date, RFC2822 style · %cr: committer date, relative · %ct: committer date, UNIX timestamp · %ci: committer date, ISO 8601-like format · %cI: committer date, strict ISO 8601 format · %d: ref names, like the --decorate option of git-log(1) · %D: ref names without the " (", ")" wrapping. · %e: encoding · %s: subject · %f: sanitized subject line, suitable for a filename · %b: body · %B: raw body (unwrapped subject and body) · %N: commit notes · %GG: raw verification message from GPG for a signed commit · %G?: show "G" for a good (valid) signature, "B" for a bad signature, "U" for a good signature with unknown validity and "N" for no signature · %GS: show the name of the signer for a signed commit · %GK: show the key used to sign a signed commit · %gD: reflog selector, e.g., refs/[email protected]{1} · %gd: shortened reflog selector, e.g., [email protected]{1} · %gn: reflog identity name · %gN: reflog identity name (respecting .mailmap, see git-shortlog(1) or git-blame(1)) · %ge: reflog identity email · %gE: reflog identity email (respecting .mailmap, see git-shortlog(1) or git-blame(1)) · %gs: reflog subject · %Cred: switch color to red · %Cgreen: switch color to green · %Cblue: switch color to blue · %Creset: reset color · %C(...): color specification, as described in color.branch.* config option; adding auto, at the beginning will emit color only when colors are enabled for log output (by color.diff, color.ui, or --color, and respecting the auto settings of the former if we are going to a terminal). auto alone (i.e. %C(auto)) will turn on auto coloring on the next placeholders until the color is switched again. · %m: left, right or boundary mark · %n: newline · %%: a raw % · %x00: print a byte from a hex code · %w([<w>[,<i1>[,<i2>]]]): switch line wrapping, like the -w option of git-shortlog(1). · %<(<N>[,trunc|ltrunc|mtrunc]): make the next placeholder take at least N columns, padding spaces on the right if necessary. Optionally truncate at the beginning (ltrunc), the middle (mtrunc) or the end (trunc) if the output is longer than N columns. Note that truncating only works correctly with N >= 2. · %<|(<N>): make the next placeholder take at least until Nth columns, padding spaces on the right if necessary · %>(<N>), %>|(<N>): similar to %<(<N>), %<|(<N>) respectively, but padding spaces on the left · %>>(<N>), %>>|(<N>): similar to %>(<N>), %>|(<N>) respectively, except that if the next placeholder takes more spaces than given and there are spaces on its left, use those spaces · %><(<N>), %><|(<N>): similar to % <(<N>), %<|(<N>) respectively, but padding both sides (i.e. the text is centered)
啊,對了,我忘了提及%C顏色的部分。不過值得一提的是,與其他命名的'--pretty ='格式一樣,'--pretty = oneline'不能通過一組固定的'%' - 指令來捕獲,因爲格式化是由特殊代碼完成的,可能並不總是等同於%的指令。這對OP意味着什麼取決於他想要的輸出。 – torek