22

I'm using Ubuntu 16.04 default terminal (it's GNOME I believe?)

The problem I'm facing is that when I use git diff command to inspect my local changes I can scroll up/down using the mouse wheel, but no new lines are showing up when I get to the bottom (so I can see only one page of changes). In order to go to the next lines I can use space or up/down arrows of the keyboard, but can I somehow make this with the mouse wheel?

BTW If I use the less command it works as expected -> scrolling down goes to new lines.

edwinksl
  • 23,569
  • 16
  • 74
  • 100
Todor
  • 2,338
  • 1
  • 15
  • 19

3 Answers3

30

Thanks to @edwinksl's answer I managed to find a solution to the problem.

So by default git uses LESS as a pager and I believe the default arguments are FRSX.

On git 1.8+ you can remove options with less -+<option>, in my case I need to remove the X option so:

git config --global --replace-all core.pager 'less -+X'

but as @pcworld mention this can cause problems with diffs that fit on a single page, thus:

git config --global --replace-all core.pager 'less -+FX'

fixed the scrolling issue for me.

Todor
  • 2,338
  • 1
  • 15
  • 19
  • 3
    I needed to add `-+F` to the options of `less` or else output that fits on one screen is empty. Note that both options combined will pipe any output of git through a pager, even if it would fit on one screen. However there is a [wrapper script for less that calls less only if output exceeds screen size](https://unix.stackexchange.com/a/329811/43920). See [comments #10 and #11 on this Debian bug](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=565699#10) and [this question on less](https://superuser.com/a/972232/199854) for more technical details. – pcworld Dec 08 '17 at 15:49
5

On Windows Terminal the answer didn't help me. Instead, I had to do the following:

git config --global --replace-all core.pager 'less --mouse'
Deividas
  • 151
  • 1
  • 2
5

From https://stackoverflow.com/a/2183920/486919, one way to do this and preserve the diff highlighting is to use git diff without a pager:

git --no-pager diff
edwinksl
  • 23,569
  • 16
  • 74
  • 100
  • Thank you for this answer, this help me find the exact solution I was looking for -> enabling the mouse wheel scrolling. While removing the pager is a good work-around I prefer to start reading diffs from the beginning. – Todor Jul 28 '16 at 12:04
  • @Todor That is fair; I agree `--no-pager` is best for short diffs but not for long ones. – edwinksl Jul 28 '16 at 12:05