Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git diff: Write output and exit instead of interactive mode

When I run git diff on my OSX command line, the output is displayed inside a less or vim interface. The interface lets me to scroll up and down, and quit using the q key.

This is very annoying, especially when there is no diff and git opens a blank screen.

Can I just write the diff (color) output the the screen without entering the interactive mode?

like image 501
Adam Matan Avatar asked Feb 20 '14 07:02

Adam Matan


People also ask

How do I exit git after diff?

Use ONLY q+enter to exit. It's possible to break out by repeatedly typing q+enter+q+enter+q+enter until the end of time no matter what the console shows.

What is A and B in git diff?

In most cases, Git picks A and B in such a way that you can think of A/- as "old" content and B/+ as "new" content. Let's look at our example: Change #1 contains two lines prepended with a "+". Since no counterpart in A existed for these lines (no lines with "-"), this means that these lines were added.

What does git diff output mean?

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.

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 .


3 Answers

Disable the interactive pager with the --no-pager option.

Usage: git --no-pager diff (note how it's not specific to git-diff, so it's usable with any git command!)

Documentation: https://git-scm.com/docs/git

Copied from https://stackoverflow.com/a/2183920/2221472

like image 160
Nathan Schubkegel Avatar answered Oct 19 '22 16:10

Nathan Schubkegel


You can also use:

git diff --exit-code
like image 28
Manveer Chawla Avatar answered Oct 19 '22 15:10

Manveer Chawla


Yes. Use:

git diff --color | cat

The --color is necessary, since by default git will not output colors if stdout is not a tty (with color support).

like image 6
fge Avatar answered Oct 19 '22 16:10

fge