Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent 'git diff' from using a pager?

Tags:

git

Is there a command line switch to pass to git diff and other commands that use the less pager by default? I know these methods exist:

  • git diff | cat... removes all syntax highlighting
  • git config --global core.pager cat sets the pager in the global .gitconfig to cat
  • export GIT_PAGER=cat

But I would prefer a command line switch.

like image 502
lprsd Avatar asked Feb 02 '10 12:02

lprsd


People also ask

How do I get out of git diff staged?

To exit this you can use: :q for exit; :h for help; Note: if you don't want to read the output in pager you can use an ENV variable GIT_PAGER to cat or you need to set core.

What is git -- No pager?

answered Jul 18, 2019 by debashis borgohain (27.5k points) --no-pager to git will tell it to not use a pager. Passing the option -F to less will tell it to not page if the output fits in a single screen. Usage: git --no-pager diff.

How does git diff change if you add the option to the command?

The git diff command displays the differences between files in two commits or between a commit and your current repository. You can see what text has been added to, removed from, and changed in a file. By default, the git diff command displays any uncommitted changes to your repository.

Why do we use git diff?

Diff command is used in git to track the difference between the changes made on a file. Since Git is a version control system, tracking changes are something very vital to it. Diff command takes two inputs and reflects the differences between them. It is not necessary that these inputs are files only.


1 Answers

--no-pager to Git will tell it to not use a pager. Passing the option -F to less will tell it to not page if the output fits in a single screen.

Usage:

git --no-pager diff 

Other options from the comments include:

# Set an evaporating environment variable to use 'cat' for your pager GIT_PAGER=cat git diff  # Tells 'less' not to paginate if less than a page export LESS="-F -X $LESS" # ...then Git as usual git diff 
like image 75
Ignacio Vazquez-Abrams Avatar answered Oct 07 '22 10:10

Ignacio Vazquez-Abrams