在控制台中显示完整的Git提交消息

时间:2012-01-11 18:45:54

标签: git logging commit

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

我正在使用的命令是git log --pretty=full

7 个答案:

答案 0 :(得分:39)

寻呼救援

git log | less

确保您没有-S on别名

此外,通常认为限制提交消息的宽度是一种好习惯。我相信一个共同的标准是78个字符(IIRC),大多数发短信的人都很好地确保了这种风格规则(自动格式化你的信息)。

更新:作为参考数据点,git-config lists

  

<强> gui.commitmsgwidth

   Defines how wide the commit message window is in the git-gui(1). "75" 
   is the default.

答案 1 :(得分:8)

我用

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

答案 2 :(得分:6)

您只需要禁用寻呼机。

git --no-pager log

我来自How do I export a git log to a text file?

答案 3 :(得分:5)

git log不支持包装提交消息,因此通常的做法是将提交消息包装为大约72个字符。有关详细讨论,请参阅this answer

但是,您应该能够使用箭头键向左和向右滚动以查看线条的其余部分。你能吗?


FWIW,我建议改变Git,允许log等包装提交消息,如果你没有任何其他需要事先包装它们。在git邮件列表上观看herehere,了解它是否随处可见。

答案 4 :(得分:2)

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

commit fe37a9ccommit 0893eecJunio C Hamano (gitster)(2016年3月29日) 请commit 7cc13c7查看Linus Torvalds (torvalds)(2016年3月16日) (由Junio C Hamano -- gitster --合并于commit cafef3d,2016年4月13日)

  

pretty:默认情况下为所选的漂亮格式启用--expand-tabs

     

&#34; git log --pretty={medium,full,fuller}&#34;和&#34; git log&#34;默认情况下   在日志消息前加4个空格,因此启用是有意义的   新的&#34; expand-tabs&#34;这些格式默认设施   添加--no-expand-tabs选项以覆盖新的默认值。

doc now reads

--expand-tabs=<n>:
--expand-tabs:
--no-expand-tabs:
  

执行选项卡扩展(在每个选项卡中添加足够的空格以填充到日志消息中的多个&#39; <n>&#39;)的下一个显示列,然后在输出中显示它。
  --expand-tabs--expand-tabs=8的简写,而且是   --no-expand-tabs--expand-tabs=0的简写,禁用标签扩展。

答案 5 :(得分:2)

您也可以使用

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)

这使您可以更好地控制要提取的内容。例如,在我的用例中,我对实际的提交消息感兴趣,这样我就可以运行一个post-commit钩子。

# get the raw body of the commit
git log --format=%B HEAD

答案 6 :(得分:0)

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

git show --format=full [hash|HEAD]