Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make git diff write to stdout?

Tags:

git

terminal

People also ask

What is the output of git diff?

Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.

Why is my git diff not working?

There is no output to git diff because Git doesn't see any changes inside your repository, only files outside the repository, which it considers 'untracked' and so ignores when generating a diff.

What does ++ mean in git diff?

When viewing a combined diff, if the two files you're comparing have a line that's different from what they were merged into, you will see the ++ to represent: one line that was added does not appear in either file1 or file2.

How do I prevent git diff from using a pager?

Git uses pager when you run git diff , git show , git grep etc. If you want to see the result without pager, just add --no-pager or -P .


By default, Git sends its diff output (and generally any output that may be more than a screenful) to the system's pager, which is a utility that prints only one screenful of output at a time. If you want to disable the pager when you run a command, pass --no-pager to Git:

$ git --no-pager <subcommand> <options>

This can be run for any Git command.

If you want to disable it by default for diff only, you can set the diff pager to cat by running:

$ git config pager.diff false

If you want to disable it by default for all commands, you can set the Git pager to cat by running:

$ git config --global core.pager cat

The following core.pager value uses less, which prints to stdout, and also has pager functionality (if required), enabling scrolling up and down (unlike cat):

$ git config --global core.pager "less -FRSX"

It immediately quits if the diff fits on the first screen (-F), outputs raw control characters (-R), chops long lines rather than wrapping (-S), and does not use termcap init/deinit strings (-X).


You can also simply use cat for any git command if you don't care about the colors.

So git diff | cat for your case.

Edit: as pointed out in the comments if you do care about the colors use:

git diff --color | cat