Search code examples
gitdiffword-wrap

How should I use git diff for long lines?


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 don't line up—making it harder to track the change.

Is there a way to prevent that problem or to simply make the lines wrap instead?

I'm running Git 1.5.5 via mingw32.


Solution

  • 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