Inpired by this great post on how to use the meld diff tool to get a nice GUI view of git diffs, I started looking for a way to get a similarly good result on the command line. That is, a diff that does not just show the whole lines that are changed, but that highlights the actually changed parts of each line. Here I document what I found.
It turned out I could even get something better, than meld, in that I can view both the removed and added part in the same view (color coded with red/green) which my brain find much easier to interpret.
So, to the steps.
First I specify that git should use some external tool for it's diffs, by editing my ~/.gitconfig file and adds this to the bottom:
[diff] external = git-wdiff
#!/bin/bash wdiff -n $2 $5|colordiff|sed -r 's/(\{\+|\+\}|\[\-|\-\])//'|less
What it does is:
EDIT: [http://chem-bla-ics.blogspot.se/ Egon Willighagen] hinted me at another way to do this, where you don't even need colordiff, but can do the coloring directly with wdiff, by using it's facility for adding arbitrary start and end sequences around the changed words. Then the command in /bin/git-wdiff would become:
#!/bin/bash diff -u $2 $5 | wdiff -n -d -w $'\033[30;31m' -x $'\033[0m' -y $'\033[30;32m' -z $'\033[0m' | less
Since I'm originally a windows user and still using it sometimes, I'm keeping an eye on the status of git on windows.
Seems like there's more to do, but some things are happening: MSysGit Seems to be the currently best solution, while GitSharp looks promising. For MSysGit there's a guide on getting started with Git and GitHub on Windows.
I ran into troubles trying to check out a specific branch from github.
I asked about it at #git on FreeNode IRC channel. I'll summarize how to do it:
First run:
git clone git://github.com/...[path to your project]...git
Then go:
git branch -a
...to see what branches you have.
I just realized that git is using vim as text editor (hope it is possible to change to nano or equivalent). Anyway, as for now I guess I better just learn som basic vim commands.
http://heather.cs.ucdavis.edu/~matloff/UnixAndC/Editors/ViIntro.html saved me.
The most important commands to remember are:
i - enter "insert mode"
a - enter "append mode"
ESC - leave "insert" or "append mode"
x - delete one character
dd - delete one line (and store it in clipboard)
ZZ - Save and close
ZQ - Close w/o saving
I found a git tutorial at http://git.or.cz/course/svn.html Looks useful for svn users, since it has the paired the corresponding git / svn commands. Another one is https://we.riseup.net/debian/git-development-howto as well.