views:

1507

answers:

6

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?

(running git 1.5.5 via mingw32)

A: 

Not a perfect solution, but gitk and git-gui can both show this information, and have scrollbars.

Peter Boughton
A: 

When in trouble, I often resort to DiffMerge. Excellent diff tool that has in-line diff highlighting. Also, in the latest versions they added a mode to have an horizontal mode.

I haven't been able to configure git to use it, though. So I do have to muck around to get both versions of the file first.

webmat
+2  A: 

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
SpoonMeiser
Thanks, that looks promising - I will try it out later.
Peter Boughton
I can confirm that setting GIT_PAGER to blank does cause the lines to wrap.It also inserts symbols making it a bit difficult to read, but if necessary I can find a different pager, so still a valid answer. :)Thanks.
Peter Boughton
What symbols does it add that make it difficult to read? I might be able to edit my answer to solve that problem too.
SpoonMeiser
Mostly "<-[m" for each newline (where <- was a single arrow character), but also markers where (I think) each colour would have started, like "<-[1m" and "<-[32m".
Peter Boughton
Does the --no-color argument help at all? I'm not sure about the newline characters.
SpoonMeiser
Yes, thanks, that prevents all the unwanted content appearing, so the newline ones must have been colour related also.
Peter Boughton
+2  A: 

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

singingfish
+2  A: 

Or if you use less as default pager just type '-S' while viewing the diff to reenable wrapping in less.

someone45
+1  A: 

You can also use git config to setup pager to wrap.

$ git config core.pager 'less -r' 

Sets the pager setting for the current project.

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

Sets the pager globally for all projects

Shoan