How to color a patch file generated from git

Viewed 518

I have a file.patch file generated from someone else. I want to review the patch file, but I would like to be able to apply my own git color config to the file.

I may not currently be in a git project directory and I may not even know what repo the patch file came from, but I just want to see basically context/additions/deletions colored with my normal git colors.

I'm looking for a pipeline solution rather than some external library. Something like: git --please-color-this file.patch | less

2 Answers
colordiff < file.patch | less -R

The 'less' command is optional but I find it useful, e.g. for scrolling, searching.

less is not the program you're looking for, the colors are not stored in the file and less doesn't understand the diff format. Instead, use a tool that understands the diff format, for instance text editors such as vscode or vim. The best program is the program you currently use for merge conflicts.

Related