Tuesday, May 3, 2011

Compare Git Branches, Compare Two Files in Different Branches

Git offers a couple of great commands for comparing branches. To get a comparison of branches in a "status" type format:

git diff --name-status branch1..branch2

Will give you output something like:

M       config/boot.rb
M       config/database.yml
M       config/deploy.rb
M       config/environment.rb
M       config/environments/development.rb
M       config/environments/production.rb
M       config/environments/staging.rb

Now that you have a list of files, you may wish to get a diff of a specific file:

git difftool branch1:config/environment.rb branch2:config/environment.rb

On OSX, this will open the awesome allowing you to compare both files.

File merge

Please note this blog is no longer maintained. Please visit CivilCode Inc.