Download and Install P4merge

The P4merge software is used to resolve the Git conflicts like comparing the files, branching, and merging the files. P4merge is a visual tool for diffing and merging files and it allows us to view the difference between files across time and across code lines.

P4merge also enables us to merge different files into one. Now let us know how to download and install and then configure with Git as follow:

  • Navigate to the page
  • Now move to the downloads tab and click on the downloads.
  • Once you are on the downloads page, then scroll down and search for P4merge: visual merge tool.
  • In that, it is automatically selected for windows and in the middle drop down select windows for 32 bit(select according to your system configuration) and click on Download in the last drop-down button.
  • Before Git prompted for the download, you will get an option for registration, you just click on the skip registration, now you can see that P4merge installer is downloading.
  • Once the download is complete, click on the software and select open to run the installer in your operating system.

Now click on the yes to install the software, and then it begins installing, On the first page of the installer, it will ask you to select the needed software to be download, then you can select the application which you required.

You just de-select the features like a visual client, the administration tool, and then the command line client except for the second one which is a visual merge tool. Once you are done with the de-selection just click on the Next.

  • In the Ready to install the apps dialogue box, click on the Install.
  • Now, the P4merge has successfully installed, and then click on the Close button.

Forking and Cloning with Git

Configuring P4merge on Windows

Let's Configure P4merge accessible from any command prompt, First thing is to test whether the P4merge is accessible or not, and this process will work with Git bash, power shell, and also with the Windows command prompt.

  • Just go to Git bash and type P4merge and press enter, Now the Git Bash replies that p4merge is not the known command.
  • This means that the p4merge is not accessible from Git, So let's exit from this and Go to the Start menu and Find the p4merge.
  • Once you click on the p4merge, it launches the choose file dialogue box, it is just to confirm that the p4merge has installed and then you can Cancel this dialogue box.

Now, let's find out the p4merge.exe file, go to the My computer, under that go to Local disk, in that select program files, there you can find the perforce folder and then, click on perforce.

You can see the p4merge application file, select the p4merge and all we need is a path to the p4merge, Then go to the address bar and click on it, you will get the address and then copy the path.

  • Go to My Computer and right-click on it, you see a small dialogue box, just select properties under that.
  • It will launch the system windows, then go to the advanced system settings, just click on it.
  • It will launch the system properties on the advanced tab.
  • Click on the environment variables under the system properties and it will launch the environment variables dialogue box.

Under the system variables, select the path and click on the Edit, then it will take you to the address path bar, hence to separate the address values, first enter the semicolon and paste the address that you copied before and then click on Ok on all the tabs and close it.

  • Now open up the Git Bash command prompt and enter the p4merge, if you come up with a dialogue box, it confirmes that, the p4merge has configured with Git.

Text Editor Configuration with Git

Configure P4merge with Git

Here I am going to configure P4merge to work with Git. First, let's find where P4merge has installed.

By default, the programs will be installed in the Local disk, under that select the program files and in that, you can see a folder by the name called perforce, which is the name of the company that makes p4merge.

Going into that folder you can see a p4merge application file, Just double-click on that, it will launch the p4merge. now, we know the location, just close and go back and then open the Git Bash.

I am going to position the Git Bash window so that, I can able to see the address path of the application file.

So by using the Git config command, am going to config Git to use p4merge as the merge resolution tool.

I will pass the command as git config --global merge.tool p4merge, because these settings are needed to be at the user level and then press enter.

The second command will tell Git where to look for the p4merge tool. git config --global mergetool.p4merge.path "c:/programfiles/perforce/p4merge.exe"

Note: the direction of the slashes uses the familiar Unix-style, as opposed to the backslash of the Windows-style.

So the next command tells Git not to prompt and not to launch p4merge, so every time we need to resolve a conflict, We will pass another command to resolve a conflict as git config --global mergetool.prompt false

Now setup the difftool configuration, same as in the last example, we are going to use a similar syntax, except use difftool, git config diff.tool p4merge and press enter and git config --global difftool.p4merge.path "c:/programfiles/perforce/p4merge.exe" and press enter.

The last command to configure out difftool is git config --global difftool.prompt false

  • Now let's check for the list of configuration we have done, git config --global --list press enter.
  • So along with the other set, we have our mergetool and difftool configuration as well.
  • So now, pass the command git config --global -e will invoke our default editor with a .gitconfig file.

Most of the configuration that is set up in the .gitconfig file is related to the difftool and merge tool. Now let's close the default window by using Ctrl+W and Alt+F4.

In the next article called Git Comparisons, you are going to understand clearly how p4merge is useful in comparing, merging, and branching.

Backing Out Changes in Git Repository

0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions