Git is a versatile tool to do version control of project code. We can develop code with slight modifications using branches in GIT. Sometimes we require to compare two branches to see what difference in that two branches. In this post, we will see how to see a difference between two branches in a different way.
Example1: Show all the files which are different between two branches.
git diff --name-only branch_1..branch_2
git diff --name-only branch_1 branch_2
git diff --name-only bug/fix_gcc_compiler...feature/test-12430 .kitchen.vagrant.yml .kitchen.yml Berksfile CHANGELOG.md attributes/default.rb files/default/nonprod_pvm_ca_cert files/default/prod_pvm_ca_cert metadata.rb recipes/cleanup.rb recipes/configure.rb recipes/install.rb recipes/install_v4.rb recipes/install_v4_audit.rb spec/unit/recipes/cleanup_spec.rb spec/unit/recipes/configure_spec.rb spec/unit/recipes/install_spec.rb spec/wbc_nix_protectv_test/default_spec.rb
This will list all the files which have difference instead of showing content.
Example2: To see the difference of file content from different branches use below command
git diff mybranch master — myfile.cs
git diff feature/test-23438 master -- metadata.rb diff --git a/metadata.rb b/metadata.rb index b373613..a794431 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ maintainer_email 'email@example.com' license 'all_rights' description 'Installs/Configures www_linuxnix_protectv' long_description 'Installs/Configures www_linuxnix_protectv' -version '1.1.1' +version '1.1.0' chef_version '>= 12.5' if respond_to?(:chef_version) supports 'redhat'
Example3: Get the difference between two branches.
git diff branch_1..branch_2
git diff feature/test-23438 master
Latest posts by Surendra Anne (see all)
- FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018
- wget download a file to a directory in Linux/Unix - June 4, 2018
- GIT: How to compare two GIT branches? - June 3, 2018