I'm trying to output a list of git-show results and pipe them into a pager.
Unfortunately I'm unable to preserve color.
This is the command I'm running:
git log -n10 | awk '{print $1}' | xargs -d '\n' -I{} bash -c 'git show {}' -- | less -MR

Without the | less -MR pipe, the output is printed in color.
I've tried less -r as well, but obviously the problem seems to be in that git show or xargs do not preserve color when they detect that their output is being piped to another command rather than to stdout.

The xargs manual says nothing about preserving color, neither does the git manual.

How do I preserve color in the less pager output?

  • I actually found the solution in man git-show as I was half-through the question, so might as well post and mark as accepted answer for the benefit of the community..
    – Petrus K.
    Jun 19, 2017 at 14:40

1 Answer 1


man git-show describes how to force-preserve color, seems to be taken from man git-diff:

       Show colored diff.  --color (i.e. without =<when>) is the same as --color=always.  <when> can be one of always, never, or auto.

Updated bash command:
git log -n10 | awk '{print $1}' | xargs -d '\n' -I{} bash -c 'git show --color=always {}' -- | less -MR

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.