git diff - handling long lines?

2019-01-12 15:53发布

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)

标签: git diff wrap
16条回答
三岁会撩人
2楼-- · 2019-01-12 15:57

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

查看更多
Fickle 薄情
3楼-- · 2019-01-12 15:58

Noone pointed out this till now. Its quite simple to remember and no extra configuration needs to be done in the git config

git diff --color | less -R
查看更多
小情绪 Triste *
4楼-- · 2019-01-12 15:59

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.

查看更多
Fickle 薄情
5楼-- · 2019-01-12 16:00

list the current/default config:

  $ git config --global core.pager  
    less -FXRS -x2

then update and leave out the -S like:

  $ git config --global core.pager 'less -FXR -x2'

the -S: Causes lines longer than the screen width to be chopped rather than folded.

查看更多
劫难
6楼-- · 2019-01-12 16:01

When you are using "git diff" and it's showing several pages(you see ":" at the end of the page)in this case you can type "-S" and press enter.(S should be capital). it will toggle fold long lines.

查看更多
甜甜的少女心
7楼-- · 2019-01-12 16:02

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

查看更多
登录 后发表回答