Using p4merge as git diff tool
Asked Answered
N

4

15

I use windows 7. I want to use p4merge as Git diff/merge tool. I follow this article and this one to setup and config p4merge:

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"

And these lines are from git config:

merge.tool=p4merge
mergetool.p4merge.path=C:/Program Files/Perforce/p4merge.exe
diff.tool=p4merge
difftool.p4merge.path=C:/Program Files/Perforce/p4merge.exe
mergetool.keeptemporaries=false
mergetool.prompt=false

Now git mergetool command works fine. But when I use git difftool command in git bash, I expect p4merge but I see internal implementation of diff in git bash.

I tried Smooth Git + P4merge but it does not work for me also I tried to do as described in External Merge and Diff Tools but I did not understand that.

Note:

When type of conflict is removed file conflict, git difftool command opens p4merge.

Nimocks answered 22/8, 2015 at 4:51 Comment(6)
Replace diff.tool=p4diff by diff.tool=p4mergeBalladmonger
@Balladmonger Please see my edit.Nimocks
Use / instead of `\` as separator perhaps solve the problem...Sc
@Sc I tried that, but did not solve problem. I edit question,please see it again.Nimocks
I also used the instructions and work with P4Merge successfully for changed files since quite a while using git difftool --staged. One thing annoys me though: the error message when files were added. p4merge wants files to compare. Is there a way to omit added files? How did you solve this?Chausses
Hi guys! Did you find the correct way for your issue ? I am in similar situation :/Sidonius
U
20

Not sure if helps, but recent versions of Git support P4Merge (I use git version 2.17.0. on Windows through MSYS2).

You can tell if this is the case or not by running git difftool --tool-help. It'll list the available tools Git can use (because they've found them in your %PATH%) and the tools it could use (if they were installed).

If p4merge is in this list then you just need to add the path where p4merge.exe resides to your %PATH% (on Windows I recommend Rapid Environment Editor for this).

After this is done you just need the following config to be in your .gitconfig

[diff]
    tool = p4merge
[merge]
    tool = p4merge

and nothing else. So remove other stuff like difftool.path and all that.

Then just use git difftool or git mergetool to your hearts content.

Note: I had a repository in which even if I did issue the git difftool or git mergetool commands P4Merge wouldn't start. I'm not sure what was the problem in that repo. However I tried creating an empty repo somewhere on my drive with git init, add a file, commit it, then modify it, then I tried difftool and it worked. So if the above description doesn't work for you chances the problem lies somewhere else. Hope this helps.

Urbane answered 19/7, 2018 at 5:8 Comment(0)
B
2

Better late than never :)

mergetool.p4merge.path should be mergetool.p4merge.cmd

Change path to cmd for both the mergetool and difftool lines.

Bohun answered 15/6, 2016 at 13:50 Comment(1)
You can use the option mergetool.p4merge.path, there will be a standard order of tabs: REMOTE, BASE, LOCAL.Erubescence
A
2

If you are on Mac don't forget to add / before Applications as in:

[mergetool "p4merge"]
    path = /Applications/p4merge.app/Contents/MacOS/p4merge

This was why P4Merge wouldn't open for me when I ran below:

git mergetool
Abb answered 18/10, 2021 at 23:16 Comment(0)
Y
0

DeviantDev has a pretty good answer for this.

Adding this to my .gitconfig worked for me...

[diff]
    tool = p4merge
[difftool]
    prompt = false
[difftool "p4merge"]
    path = C:\\Program Files\\Perforce\\p4merge.exe
[merge]
    tool = p4merge
[mergetool "p4merge"]
    path = C:\\Program Files\\Perforce\\p4merge.exe
[mergetool]
    keepBackup = false
Yance answered 11/1, 2023 at 17:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.