1

When there are no changes in a git repo, git diff used to immediately return with no output. Since git 2.9, such git diff commands open a less-like window with no text, which I have to manually close by pressing q. Is there a way to restore the old git diff behavior?

EDIT

Title changed.

git 2.9 is actually unrelated, this new behavior is due to having recently introduced LESS="-Ri" in my environment. How should I change this variable to achieve what I want?

eang
  • 1,615
  • 7
  • 21
  • 41
  • 2
    Very related with exhaustive answers: http://stackoverflow.com/questions/2183900/how-do-i-prevent-git-diff-from-using-a-pager – eckes Jul 05 '16 at 13:45
  • 1
    `alias git='LESS= git'` runs interactive `git` commands in Bash with `LESS` set to nothing. Adapting to set it to something else should be obvious. Maybe `alias git='LESS="-F${LESS#-}" git'` to add `-F` but otherwise keep your global `LESS` options. – tripleee Jul 05 '16 at 13:57

2 Answers2

4

Try to use LESS="-RFi"

From man:

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

If you don't want to change your environment LESS variable, you can archive the same via .gitconfig:

[pager]
    log  = less -FRX
    diff = less -FRX
    show = less -FRX
qehgt
  • 2,972
  • 1
  • 22
  • 36
  • `LESS="-RFi"` seems to potentially break e.g. `git show HEAD`, but the pager options in `.gitconfig` work fine, thanks! – eang Jul 06 '16 at 18:57
0

If you ask for

git --no-pager diff

the behavior should be the same again.

eckes
  • 64,417
  • 29
  • 168
  • 201