ANSI color in git is not displayed correctly

前端 未结 8 1022
一向
一向 2020-12-12 18:00

Recently, I switched to SLES 11. I found a problem for git command. All the ANSI color could not be rendered. Instead, it shows the ANSI code like this:

*ESC

相关标签:
8条回答
  • 2020-12-12 18:21

    OK, I got it. This problem is to do with the variable LESS.

    following line resolve this problem:

    export LESS="-erX"
    
    0 讨论(0)
  • 2020-12-12 18:22

    Whoever ever winds up here, in my case it was solved by setting core.pager to an empty string, instead of unsetting it:

    git config --global core.pager ''
    

    This was from https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration

    0 讨论(0)
  • 2020-12-12 18:25

    The problem, as others have noted, is that your terminal is fine, but when Git invokes the pager, it's not interpreting the ANSI color codes correctly.

    I'd start out by unsetting LESS in your environment; it sounds like you might have previously been setting it to something obscuring what Git needs. If that solves it, there you are. If you really must customize LESS, note that Git starts out with FRSX as default, so be wary of changing those if you don't need to.

    If you do for whatever reason want LESS in your environment different from what you want for Git, the ideal way to deal with Git and the pager is through the core.pager config variable. To quote the manpage:

    The command that git will use to paginate output. Can be overridden with the GIT_PAGER environment variable. Note that git sets the LESS environment variable to FRSX if it is unset when it runs the pager. One can change these settings by setting the LESS variable to some other value. Alternately, these settings can be overridden on a project or global basis by setting the core.pager option. Setting core.pager has no affect on the LESS environment variable behaviour above, so if you want to override git’s default settings this way, you need to be explicit. For example, to disable the S option in a backward compatible manner, set core.pager to less -+$LESS -FRX. This will be passed to the shell by git, which will translate the final command to LESS=FRSX less -+FRSX -FRX.

    That, combined with some knowledge of the options you want, should get you where you want to be. (The fancy backward-compatible method works by disabling all options currently in LESS, then adding back in the ones you want.)

    0 讨论(0)
  • 2020-12-12 18:26

    For me, this did not work:

    git config --global core.pager less -R

    So instead i appended the following to my ~/.gitconfig file

     [core]
         pager = less -R
    

    To test it i did

    git log --graph --pretty=format:"%C(yellow)%h%Creset%C(blue)%d%Creset %C(white bold)%s%Creset %C(white dim)(by %an %ar)%Creset" --all

    0 讨论(0)
  • 2020-12-12 18:26

    I had similar problem with ANSI color escape sequences in Git for Windows v2.7.1 in Laravel Artisan and Symfony consoles. Here mentioned LESS solution didn't solve the problem.

    Since Git for Windows opens terminal with bash --login -i, this line entered after terminal started did work for me:

    bash
    
    0 讨论(0)
  • 2020-12-12 18:32

    In git, you can change your pager to use the -R option:

    git config --global core.pager "less -R"
    
    0 讨论(0)
提交回复
热议问题