Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In order to get coloured output from all git commands, I set the following:

git config --global color.ui true

However, this produces an output like this for git diff, git log

git diff screenshot

whereas commands like git status display fine

git status screenshot

Why is it not recognizing the escaped color codes in only some of the commands and how can I fix it?

I'm using iTerm 2 (terminal type xterm-256color) on OS X 10.8.2 and zsh as my shell

zsh --version
zsh 5.0.0 (x86_64-apple-darwin12.0.0)

git --version                                                                                                                      
git version 1.7.9.6 (Apple Git-31.1)
share|improve this question

1 Answer 1

up vote 19 down vote accepted

You're seeing the escape sequences that tell the terminal to change colors displayed with the escape character shown as ESC, whereas the desired behavior would be that the escape sequences have their intended effect.

Commands such as git diff and git log pipe their output into a pager, less by default. Git tries to tell less to allow control characters to have their control effect, but this isn't working for you.

If less is your pager but you have the environment variable LESS set to a value that doesn't include -r or -R, git is unable to tell less to display colors. It normally passes LESS=-FRSX, but not if LESS is already set in the environment. A fix is to explicitly pass the -R option to tell less to display colors when invoked by git:

git config --global core.pager 'less -R'

If less isn't your pager, either switch to less or figure out how to make your pager display colors.

If you don't want git to display colors when it's invoking a pager, set color.ui to auto instead of true.

share|improve this answer
    
Ah, thanks. While I knew that less needed -R to display colors, I forgot that git log and git diff piped output to less. Thanks :) –  user32465 Feb 16 '13 at 1:10
1  
Thank you! I hadn't noticed that the default ~/.profile in FreeBSD had PAGER=more; export PAGER –  Jeffrey Goldberg Mar 3 at 22:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.