2012年9月29日 星期六

git-diff between branches

git-diff on different branches.md

Before we diff, we have 4 branches :

tomteki-Mac-Pro:HearingLite tom$ git branch

TestUSB
* master
multiLanguage
testKbd

tomteki-Mac-Pro:HearingLite tom$

We want to diff the EditProfileViewController.m, to get the idea of where it is :

tomteki-Mac-Pro:HearingLite tom$ git diff --name-only master testKbd | grep EditProfileViewController

Classes/EditProfileViewController.h
Classes/EditProfileViewController.m
HearingLite/EditProfileViewController.h
HearingLite/EditProfileViewController.m

tomteki-Mac-Pro:HearingLite tom$

The above command will diff between two branches (testKbd and master).

Assume it is restructured from HearingLite/ path to Classes/ path (if doesn't , git ls-files can help ), the next thing to do is really diff them :

 git diff master:Classes/EditProfileViewController.m testKbd:HearingLite/EditProfileViewController.m

In this note, we use the 'git diff --name-only' to get the path of our target file. And use 'git diff [branch] : [file path]' to diff the file in various branches.