在控制台中显示完整的git commit消息

ale*_*ias 42 git logging commit

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

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

seh*_*ehe 40

寻呼机救援

git log | less
Run Code Online (Sandbox Code Playgroud)

确保没有-S on别名

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

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

gui.commitmsgwidth

   Defines how wide the commit message window is in the git-gui(1). "75" 
   is the default.
Run Code Online (Sandbox Code Playgroud)


Ass*_*mer 10

我用

git lg | fold --width=1000
Run Code Online (Sandbox Code Playgroud)

其中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
Run Code Online (Sandbox Code Playgroud)

它看起来像这样:

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


Kus*_*esh 7

您只需要禁用寻呼机.

git --no-pager log
Run Code Online (Sandbox Code Playgroud)

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


s4y*_*s4y 5

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

您应该能够使用箭头键向左和向右滚动以查看该行的其余部分.你能?


FWIW,我建议对Git进行更改log,如果你没有任何其他需要事先包装它们,那么允许等包装提交消息.观看这里这里的git邮件列表,看看它是否随处可见.


pol*_*ise 5

您也可以使用

git log --format=<format> [hash|HEAD]
Run Code Online (Sandbox Code Playgroud)

其中<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)
Run Code Online (Sandbox Code Playgroud)

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

# get the raw body of the commit
git log --format=%B HEAD
Run Code Online (Sandbox Code Playgroud)