Skip to content

Instantly share code, notes, and snippets.

@Rishav-Git
Last active January 17, 2018 04:42
Show Gist options
  • Save Rishav-Git/1f4a6f74055afe17ba800fb568c01a22 to your computer and use it in GitHub Desktop.
Save Rishav-Git/1f4a6f74055afe17ba800fb568c01a22 to your computer and use it in GitHub Desktop.
Comparing files in the master branch with files in the developer branch

Comparing files in the master branch with files in the developer branch

Creating a repository:

1)Copy the files to a directory.

2)Make the directory a git repository using the command:

$git init

3)Now add the files to the staging area using the command:

$git add .

This will add all the files to the staging area.

4)Now commit the changes made to the repository with a message.

$git commit -m “Adding files to the master branch”

 Working as a developer:

Working on feature, the developer needs to create a branch and then work on that feature.

1)To create branch, we use the command:

$git branch <branch name>

2)To go to the created branch, we use the command:

$git checkout <branch name>

3)The developer can then work on a feature by adding, editing and deleting files.

Now in order to compare the files in the developer’s branch with the files in the master branch we use the tool p4merge.

 Setting up the p4merge tool:

1)First, download the p4merge tool and install it.

2)Open git bash.

3)Use the following commands:

  •	git config --global merge.tool p4merge
  
  •	git config --global mergetool.p4merge.path “C:/Program Files/Perforce/p4merge.exe”
  
  •	git config --global diff.tool p4merge
  
  •	git config --global difftool.p4merge.path “C:/Program Files/Perforce/p4merge.exe” 

The path is where the p4merge.exe program is located.

4)Using the above commands, we configure the difftool and mergetool as p4merge.

Comparing Two Files Using p4merge:

The developer wants to compare his/her file which is the developer’s branch to the file in the master branch. For this comparison the command used is:

     $git difftool master..developer

After using this command the developer will be prompted :

		  Launch 'p4merge' [Y/n]? 

After pressing Y, p4merge program will load, comparing the two files.

If we want to list all the files which are in the developer branch and are different from that of master branch, then we use the command:

	  	$git diff --name-only master..developer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment