How should I use git diff for long lines?

后端 未结 15 2419
庸人自扰
庸人自扰 2020-12-04 05:37

I\'m running git-diff on a file, but the change is at the end of a long line.

If I use cursor keys to move right, it loses colour-coding—and worse the lines do

相关标签:
15条回答
  • 2020-12-04 05:44

    Eight years later I find a superior answer, from https://superuser.com/questions/777617/line-wrapping-less-in-os-x-specifically-for-use-with-git-diff:

    git config core.pager `fold -w 80 | less`
    

    Now you pipe the git diff through fold, first, then to less: wrapped, less page-height is correct, keep syntax highlighting.

    0 讨论(0)
  • 2020-12-04 05:48

    To use less as the pager and make line wrapping permanent you can simply enable the fold-long-lines option:

    git config --global core.pager 'less -+S'
    

    This way you do not have to type it while using less.

    Cheers

    0 讨论(0)
  • 2020-12-04 05:48

    Just googled up this one. GIT_PAGER='less -r' works for me

    0 讨论(0)
  • 2020-12-04 05:51

    The display of the output of git diff is handled by whatever pager you are using.

    Commonly, under Linux, less would be used.

    You can tell git to use a different pager by setting the GIT_PAGER environment variable. If you don't mind about paging (for example, your terminal allows you to scroll back) you might try explicitly setting GIT_PAGER to empty to stop it using a pager. Under Linux:

    $ GIT_PAGER='' git diff
    

    Without a pager, the lines will wrap.

    If your terminal doesn't support coloured output, you can also turn this off using either the --no-color argument, or putting an entry in the color section of your git config file.

    $ GIT_PAGER='' git diff --no-color
    
    0 讨论(0)
  • 2020-12-04 05:53

    Since Git 1.5.3 (Sep 2007)

    a --no-pager option has been available.

    git --no-pager diff
    

    How do I prevent git diff from using a pager?

    Example

    Starting with v2.1, wrap is the default

    Git v2.1 Release Notes

    0 讨论(0)
  • Not a perfect solution, but gitk and git-gui can both show this information, and have scrollbars.

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