git – how to diff two branches

It is sometimes useful to be able to diff two branches in git. This can be useful to understand the changes in a git repository better. For the purpose of this article we we clone Sunshine-Version-2 repositoty at https://github.com/udacity/Sunshine-Version-2.

$ git clone https://github.com/udacity/Sunshine-Version-2
$ git checkout 1.01_hello_world
$ git checkout 1.03_update_fragment_layout

git – diff local branches

To diff local branches in git

$ git diff 1.01_hello_world..1.03_update_fragment_layout

git – diff local branches name only

To diff and print only names two local branches in git

$ git diff --name-only 1.01_hello_world..1.03_update_fragment_layout
app/src/main/res/layout/fragment_main.xml
app/src/main/res/layout/list_item_forecast.xml

git – diff local branches – stat

To diff and print only stat two local branches in git

$ git diff --stat 1.01_hello_world..1.03_update_fragment_layout
app/src/main/res/layout/fragment_main.xml      | 18 ++++++++++++------
app/src/main/res/layout/list_item_forecast.xml |  8 ++++++++
2 files changed, 20 insertions(+), 6 deletions(-)

git – diff local branches – with color

To diff with color two local branches in git

$ git diff --color 1.01_hello_world..1.03_update_fragment_layout

Here is how it looks:
git-color-diff

git – diff remote branches

To diff local branches in git

$ git diff origin/1.01_hello_world..origin/1.03_update_fragment_layout
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments