在控制台中显示完整的 Git 提交消息,无需调整窗口大小

问题描述 投票:0回答:7

我正在尝试在控制台中输出完整的提交消息,并且我能够获取该消息,但是为了查看完整的消息,我必须不断调整控制台窗口的大小以显示更多信息。我在 Windows 上使用 Cygwin。

我使用的命令是

git log --pretty=full

git terminal git-log
7个回答
48
投票

寻呼机来救援

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.

25
投票

您也可以使用

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

14
投票

我用

git lg | fold --width=1000

其中

lg
在 .gitconfig 中定义如下

[alias]
    lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative

看起来像这样:

git log showing full comments wrapping in terminal


13
投票

您只需禁用寻呼机即可。

git --no-pager log

这是我从如何将 git 日志导出到文本文件?


6
投票

git log
不支持包装提交消息,因此常见的做法是将提交消息包装为大约 72 个字符。请参阅此答案以获取更多讨论。

不过,您应该能够使用箭头键左右滚动以查看该行的其余部分。可以吗?


FWIW,如果您没有任何其他需要提前包装它们,我建议对 Git 进行更改,允许

log
等包装提交消息。观看 git 邮件列表上的 herehere 以了解它是否会去任何地方。


4
投票

使用

git log --pretty=(medium,full,fuller)
(意思是不使用
pretty=format
)时查看更多内容的另一个选项是能够删除在每条日志消息开头添加的空格缩进(4 个空格)(git 2.9,2016 年 6 月):

请参阅 Junio C Hamano (gitster)提交 fe37a9c

提交 0893eec
(2016 年 3 月 29 日)
请参阅 Linus Torvalds (torvalds)
commit 7cc13c7
(2016 年 3 月 16 日)。
(由 Junio C Hamano --
gitster
--
commit cafef3d 合并,2016 年 4 月 13 日)

pretty
:默认为选定的漂亮格式启用
--expand-tabs

默认为

git log --pretty={medium,full,fuller}
”和“
git log
” 在日志消息前添加 4 个空格,因此启用 这些格式默认使用新的“
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
的简写,它禁用选项卡扩展。


4
投票

如果您需要查看单个提交的完整多行消息,请使用

git show --format=full [hash|HEAD]
© www.soinside.com 2019 - 2024. All rights reserved.