2

Basically, I want git diff and git log to pipe to less automatically, so that my prompt isn't cluttered with code.

When I run "git diff", for example, I get the following output

WarriorPoet@JARVIS: /mnt/c/../Robot_one -> git diff
diff --git a/lib/movement/movement.cpp b/lib/movement/movement.cpp
index 523c2c1..3e323d6 100644
--- a/lib/movement/movement.cpp
+++ b/lib/movement/movement.cpp
@@ -1,6 +1,10 @@
// bunch
// of
// code
WarriorPoet@JARVIS: /mnt/c/../Robot_one -> _

My global .gitconfig has the following:

[core]
   whitespace = cr-at-eol
   excludesfile = ~/.gitignore
   pager = less -R
[pager]
   diff = true

and I have no local .gitconfig file that I know of.

EDIT:

running 'git config --global -l | grep pager'

core.pager=less -R
pager.diff=true

And running 'git config --local -l | grep pager' yields no output, while 'git config --system -e' is empty.

I am running Bash on Ubuntu on Windows, on windows 10.

xhienne
  • 5,738
  • 1
  • 15
  • 34
WarriorPoet
  • 41
  • 1
  • 4

2 Answers2

1

I have no local .gitconfig file that I know of.

You can check that with git config -l --show-origin

See if the project stevemao/diff-so-fancy can be of interest to cleanup git diff.

You can then use page to pipe its result:

git config --global core.pager "diff-so-fancy | less --tabs=4 -RFX"

That gives you:

git diff vs git diff --color | diff-so-fancy

https://cloud.githubusercontent.com/assets/39191/13622719/7cc7c54c-e555-11e5-86c4-7045d91af041.png


ayorgo points out in the comments to "How do I prevent 'git diff' from using a pager?"

 git config --global core.pager 'less -+F -+X'
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • [This](https://stackoverflow.com/questions/2183900/how-do-i-prevent-git-diff-from-using-a-pager/2183920#comment27691311_2183900) ended up working for me eventually. Otherwise my terminal would still get polluted with the output for some reason. – ayorgo Oct 12 '21 at 17:11
  • @ayorgo Thank you. I have included your comment in the answer for more visibility. – VonC Oct 12 '21 at 19:50
1

If you are in the repo where you want to diff, you can check all the config values (including local config values) with

git config -l

This will list the key value pairs. You can additionally filter for the pager values with

git config -l | grep pager

to see if any local config values are overwriting your global config value.

Additionally if you are on an older version of git (I believe less than 2.8) git config -l --show-origin won't work. You can use, as a work around,

git config --system -e

git config --global -e

git config --local -e

to open your configured editor with the config file and find the location. eg if Notepad++ is your configured editor then the file location will display at the top.

dude
  • 21
  • 2
  • I've edited my original question with outputs from these commands. I don't seem to have any additional .gitconfig files that override my global. Is this an artifact from me running bash on windows? – WarriorPoet Mar 19 '17 at 09:31
  • Does the git config --local -l without grep yield any results? It needs to be run from within the repo to get any results – dude Mar 19 '17 at 11:17
  • You can also set an environment variable for GIT_TRACE=true and see if git is actually executing your less command. eg I get output like this **run-command.c:336 trace: run_command: 'less -RFX'** – dude Mar 19 '17 at 12:13