How to wrap git commit comments?

后端 未结 15 1926
野性不改
野性不改 2020-12-01 01:01

Is there a way to wrap git commit comments (when viewed via git log), so they are not cut off at the end of the line? It seems like there should be a pretty sim

相关标签:
15条回答
  • 2020-12-01 01:03

    So I was looking for a solution to a similar problem to this, and came across this question. In my case I'm running git show and I have 2 lines where the change is in a single word, towards the end of a very long line. I ended up solving this with a similar approach to how I do with git diff, using the --word-diff-regex option.

    git show --color --word-diff-regex="[^[:space:],]+" 55de9c954d5d74a185879d3441a69cc1889c00f1 |more

    0 讨论(0)
  • 2020-12-01 01:07

    This has helped me.

    git --no-pager log WhateverBranch | head -n40
    

    Typically the branch is large, so, piping it to head and using the -n switch lets you grab only the most recent 40 (or however many) lines of output that you need, and it should wrap (no need to scroll). Be aware this approach also lacks the color formatting.

    0 讨论(0)
  • 2020-12-01 01:07

    For those using SourceTree, there's a setting (Options > General) that will show a column guide in the commit message:

    0 讨论(0)
  • 2020-12-01 01:12

    At least in git version 1.7.9.5, git log does support line wrapping. From git help log:

     PRETTY FORMATS
       %w([<w>[,<i1>[,<i2>]]]): switch line wrapping
    

    So, for example, the following wraps the long subjects at 72 columns:

    alias gl='git log --format="%C(yellow)%h %an %ad%C(reset)%n%w(72,1,2)%s"'
    

    (Agreed that commit formatting conventions should be followed instead of relying on this. However, this might prove useful until the day comes when everybody knows and respects the conventions.)

    0 讨论(0)
  • 2020-12-01 01:14

    Or you can change your pager to use less -R

    $ git config --global core.pager 'less -R'
    

    This will tell less to stop trying to control how the screen is formatted (you can normally scroll right and left during a git log using arrow keys). And as the less manual says "Thus, various display problems may result, such as long lines being split in the wrong place." Which is what you want, you want the line ending to appear at the right of your screen (the wrong place) instead of where the comment author put it.

    Also to note, pressing the right arrow key without modifying your pager, will let you see more of the code. Which is my preferred method.

    0 讨论(0)
  • 2020-12-01 01:14

    As VonC mentioned, you may want to wrap your commit messages to 72 characters and kill many birds with one stone. This git hook auto-wraps your commit messages and works with any editor: https://github.com/surabhigupta/AutoWrapSeventyTwo

    0 讨论(0)
提交回复
热议问题