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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8824863/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:43:08  来源:igfitidea点击:

Show full Git commit message in console

gitloggingcommit

提问by alexdmejias

I'm trying to output the full commit message in the console and I am able get the message, however in order to see the full message I have to keep resizing the console window in order to reveal more. I am on Windows using Cygwin.

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

The command I'm using is git log --pretty=full.

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

采纳答案by sehe

pagers to the rescue

寻呼机来救援

git log | less

Make sure you don't have -S on an alias for less

确保您在别名上没有 -S 更少

Also, it is generally considered good practice to limit the width for commit messages. I believe a common standard is 78 chars (IIRC), and most texteditors do a good job of ensuring such style rules (auto formatting your message).

此外,通常认为限制提交消息的宽度是一种很好的做法。我相信一个通用标准是 78 个字符 (IIRC),并且大多数文本编辑器在确保此类样式规则(自动格式化您的消息)方面做得很好。

Update: As a reference data point, git-configlists:

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

gui.commitmsgwidth

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

gui.commitmsgwidth

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

回答by Assaf Shomer

I use

我用

git lg | fold --width=1000

where lgis defined in .gitconfig like so

wherelg在 .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

It looks like that:

它看起来像这样:

git log showing full comments wrapping in terminal

git log 显示在终端中包装的完整评论

回答by Kushdesh

You'll just need to disable the pager.

您只需要禁用寻呼机。

git --no-pager log

This I got from How do I export a git log to a text file?

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

回答by polarise

You can also use

你也可以使用

git log --format=<format> [hash|HEAD]

where <format>can be one of the following:

where<format>可以是以下之一:

The placeholders are:

占位符是:

# 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)

This gives you so much more control over what to extract. For example in my use-case I'm interested in the actual commit message so that I can run a post-commit hook.

这使您可以更好地控制要提取的内容。例如,在我的用例中,我对实际提交消息感兴趣,以便我可以运行提交后挂钩。

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

回答by s4y

git logdoesn't support wrapping commit messages, so common practice is is to wrap your commit messages to about 72 characters. See this answerfor more discussion.

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

You should be able to use the arrow keys to scroll left and right to see the remainder of the line, though. Can you?

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



FWIW, I'm proposing a change to Git that would allow logand the like to wrap commit messages, if you don't have any other need to wrap them in advance. Watch hereand hereon the git mailing list to find out if it goes anywhere.

FWIW,log如果您没有任何其他需要提前包装它们,我建议对 Git 进行更改,以允许包装提交消息等。看这里这里的git的邮件列表,以找出是否它去任何地方。

回答by VonC

Another option to see more when using git log --pretty=(medium,full,fuller)(meaning when not using a pretty=format), is the ability to remove the space indentation (4 spaces) added at the beginning of each log message (git 2.9, June 2016):

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

See commit fe37a9c, commit 0893eec(29 Mar 2016) by Junio C Hamano (gitster).
See commit 7cc13c7(16 Mar 2016) by Linus Torvalds (torvalds).
(Merged by Junio C Hamano -- gitster--in commit cafef3d, 13 Apr 2016)

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

pretty: enable --expand-tabsby default for selected pretty formats

"git log --pretty={medium,full,fuller}" and "git log" by default prepend 4 spaces to the log message, so it makes sense to enable the new "expand-tabs" facility by default for these formats.
Add --no-expand-tabsoption to override the new default.

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

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

The doc now reads:

文档现在显示

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

Perform a tab expansion (replace each tab with enough spaces to fill to the next display column that is multiple of '<n>') in the log message before showing it in the output.
--expand-tabsis a short-hand for --expand-tabs=8, and
--no-expand-tabsis a short-hand for --expand-tabs=0, which disables tab expansion.

<n>在将日志消息显示在输出中之前,在日志消息中执行选项卡扩展(用足够的空格替换每个选项卡以填充到下一个显示列是“ ”的倍数)。
--expand-tabs是 的简写--expand-tabs=8
--no-expand-tabs是 的简写--expand-tabs=0,它禁用选项卡扩展。

回答by Micha? Szajbe

If you need to see the full, multi-linemessage of a single commit use

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

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