Setup p4merge as a diff tool for git

If you are already here, you prob­a­bly know that p4merge is a really amaz­ing tool for visu­al­iz­ing diffs. To set it up with git on an ubuntu sys­tem, sim­ply do the following

  • Down­load p4merge from their site.
  • Copy it to a con­ve­nient direc­tory. I usu­ally copy to a file called programs
  • Run the fol­low­ing commands
gunzip p4v.tgz
tar xvf p4v.tar
ln -s /path_to_your_folder/p4v-2014.2-123456/bin/p4merge /usr/local/bin/p4merge

That installs p4merge for you as a com­mand line tool.

Now, to set it up with git, set the fol­low­ing con­fig parameters

git config --global merge.tool p4merge
git config --global mergetool.keepBackup false
git config --global mergetool.p4merge.path /usr/local/bin/p4merge

From then on, to see diffs, you can run the command

git difftool

to see diffs in the work­ing dir vs staged or

git difftool --cached

to see diffs between staged and head.

In case you feel that you are annoyed by the prompts for each file, just set this config

git config --global mergetool.prompt false

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *