At first, it seemed annoying, but now I really like that git uses a pager when it has to present something (e.g. a log or a diff) that is longer than your screen. Git even provides a built in option --color to show you a diff with helpful colors. I use this option all the time and made a shortcut dic for it with the following command
git config --global alias.dic "diff --color"
Also possible is to edit your ~/.gitconfig directly so you have something like the following in there:
[alias]
di = diff
dic = diff --colorNow I just do
git dicand I get a nice paged and color highlighted diff.
This is a so I-wonder-how-I-could-live-without-it thingy that I wanted the same when working with Subversion or CVS. These guys don't have color highlighting built in, but luckily there is this standalone "diff colorizer" colordiff to help us out. Colordiff should be available at a sufficiently recent Linux package manager near you (Ubuntu has it since 6.06 for example), otherwise installing it manually is not that hard (it's mainly one perl script and some config files).
If we also add a pager like "less" to the mix, we can mimic the behavior of git. To do so, I added two little scripts to my $PATH.
The first one is cvscolordiff.sh:
#!/bin/sh cvs diff -bup "$@" | colordiff | less -R
and the one for Subversion is svncolordiff.sh:
#!/bin/sh svn diff --diff-cmd colordiff -x "-u -w -p" "$@" | less -R
I first tried with constructing bash aliases, but then things go wrong when you try to use arguments to only see diffs of certain files for example. The scripts above take care of this with the "$@" magic, so I can do things like
svncolordiff.sh foo.cpp bar.py
Also note (in case your wondering) the -R option for less. This options makes sure less presents nice colors instead of spitting color control character garbage at you.
Thanks for the tips! You
Thanks for the tips!
You could create a bash function like so in your ~/.bashrc.
Then you wouldn't need to invoke with .sh or keep it in a seperate script.
function cvsdiff {
cvs diff -bup "$@" | colordiff | less -R
}
color diff in git
You can also just do `git config --global color.ui true` to tell git to use colors for pretty much everything, including not just diffs, but also `git status`, `git add -p`, etc.
very useful thanks
very useful thanks
Thanks
Thank you so much! :)
Post new comment