Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scrolling down git diff from mac terminal

Tags:

git

macos

I am using git on terminal on OS X 10 Yosemite.

When I do git diff I get long list of changes and sometimes I just need to scroll to the end but I couldn't figure out a way to do that other than to hold the keydown on MacBook pro and then it scrolls slowly.

if I press FN+down key then it does not scroll unless I have made the scroll down journey already down using the down button, but does not go further down...

any advice will be appreciate this is very annoying... :(

like image 809
Ahmed Avatar asked Sep 09 '15 00:09

Ahmed


People also ask

How do you scroll down in Mac terminal?

You can scroll the screen while holding fn or Shift ⇧ key. You can disable this completely by unticking: Terminal Preferences → Profiles → Keyboard → Scroll Alternate Screen.

How do you get to the bottom of a git log?

You can press q to exit. git hist is using a pager tool so you can scroll up and down the results before returning to the console.


2 Answers

git diff uses the same pager as less Unix command.

  • Use keys d and u to go down / up half pages (forward / backward technically)
  • Jump to last line: G
  • Use h if you want to display the help

Another trick is storing the diff as a patch file like they used to do in the email days! Then you can open up the patch in any program (Sublime has syntax highlight red/green)

Some examples:

git diff master > ~/patch

git show someCommitSHA > ~/patch

git diff master myBranch -- *.js *.css > ~/patch patch of js & css diff from master


git apply ~/patch

Normally you would use the patch by applying the diff, but you can just open the file in any text editor. It's useful if you don't want to make a full commit out of your diff, but still want to use it somewhere else or send it to a friend


You can also use git diff master | grep -C 2 someKeyword to show diff +/- 2 lines around some keyword

like image 158
neaumusic Avatar answered Oct 02 '22 08:10

neaumusic


git config --global core.pager "less -+\$LESS -RS"

On my new macOS laptop, that got the git log scroll working as I'd expect (page up / page down buttons working, color, wheel scroll).

Why does this work? Per the git-config manpage:

Note that git sets the LESS environment variable to FRSX if it is unset when it runs the pager.

Per the less manpage:

-X Disables sending the termcap initialization and deinitialization strings to the terminal. This is sometimes desirable if the deinitialization string does something unnecessary, like clearing the screen.

I don't actually know what any of that means, but that X breaks page up / page down / scroll wheel.

-F Causes less to automatically exit if the entire file can be displayed on the first screen.

If you don't have X, then F breaks when there's no paging, presumably because less exits immediately and something prevents it from printing directly to the terminal.

like image 22
ognockocaten Avatar answered Oct 02 '22 07:10

ognockocaten