我正在尝试在控制台中输出完整的提交消息,并且我能够获取该消息,但是为了查看完整的消息,我必须不断调整控制台窗口的大小以显示更多信息。我在 Windows 上使用 Cygwin。
我使用的命令是
git log --pretty=full
。
寻呼机来救援
git log | less
确保别名上没有 -S 来减少
此外,限制提交消息的宽度通常被认为是良好的做法。我相信通用标准是 78 个字符 (IIRC),并且大多数文本编辑器在确保此类样式规则(自动格式化您的消息)方面做得很好。
git-config
列出:
gui.commitmsgwidth
Defines how wide the commit message window is in the git-gui(1). "75" is the default.
您也可以使用
git log --format=<format> [hash|HEAD]
其中
<format>
可以是以下之一:
占位符是:
# see man git-log PRETTY FORMATS section
%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, "X" for a good signature that has expired, "Y" for a good signature made by an expired key, "R"
for a good signature made by a revoked key, "E" if the signature cannot be checked (e.g. missing key) 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/stash@{1} or refs/stash@{2 minutes ago}; the format follows the rules described for the -g option. The portion before the @ is the refname as given on the command line (so git log
-g refs/heads/master would yield refs/heads/master@{0}).
%gd: shortened reflog selector; same as %gD, but the refname portion is shortened for human readability (so refs/heads/master becomes just master).
%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 under Values in the "CONFIGURATION FILE" section of git-config(1); 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) -%(trailers): display the trailers of the body as interpreted by git-interpret-trailers(1)
这使您可以更好地控制提取的内容。例如,在我的用例中,我对实际提交消息感兴趣,以便我可以运行提交后挂钩。
# get the raw body of the commit
git log --format=%B HEAD
使用
git log --pretty=(medium,full,fuller)
(意思是不使用 pretty=format
)时查看更多内容的另一个选项是能够删除在每条日志消息开头添加的空格缩进(4 个空格)(git 2.9,2016 年 6 月):
请参阅 Junio C Hamano (gitster
)提交 fe37a9c、
提交 0893eec(2016 年 3 月 29 日)。
torvalds
)的commit 7cc13c7(2016 年 3 月 16 日)。
gitster
-- 于 commit cafef3d 合并,2016 年 4 月 13 日)
默认为
:默认为选定的漂亮格式启用pretty
--expand-tabs
“
”和“git log --pretty={medium,full,fuller}
” 在日志消息前添加 4 个空格,因此启用 这些格式默认使用新的“git log
”功能。expand-tabs
添加选项以覆盖新的默认值。--no-expand-tabs
--expand-tabs=<n>:
--expand-tabs:
--no-expand-tabs:
在日志消息中执行选项卡扩展(用足够的空格替换每个选项卡,以填充到是“
”倍数的下一个显示列),然后再在输出中显示它。<n>
是--expand-tabs
的简写,并且--expand-tabs=8
是--no-expand-tabs
的简写,它禁用选项卡扩展。--expand-tabs=0
如果您需要查看单个提交的完整多行消息,请使用
git show --format=full [hash|HEAD]