p4merge error [GIT]
Asked Answered
F

2

28

I am trying to use p4merge with git but I am getting:

Error starting p4merge: "path/myFile" is (or points to) an invalid file (this lists the BASE, LOCAL, REMOTE, and standard version of the file).

Git tells me about the conflict then it asks if I wanna start the mergetool configured (p4merge) and then I get the error above.

Additional note: it happens with any file!

Any clue about what this is and how to fix it?

Figurehead answered 14/5, 2009 at 22:48 Comment(3)
Maybe include your section in .gitconfig where you configure the merge tool and the full error message? Do you have spaces in a filename or something?Unschooled
nope no spaces in filename - i configured git using this question: stackoverflow.com/questions/426026/…Figurehead
Possible duplicate of git diff tmp file invalid on windows when using external program on Windows 7Dobrinsky
T
40

This worked for me using msysGit on windows 7:

git config --global merge.tool p4merge
git config --global mergetool.p4merge.cmd 'p4merge $BASE $LOCAL $REMOTE $MERGED'

Not sure why but the quoting screwed things up for me.

Ty answered 2/8, 2009 at 2:2 Comment(8)
Switched from one Win 8 machine to another, both using git bash and had to do this also, thanks!Pantia
Guess I should have mentioned that I use Powershell, so I'm not sure on about cmd.exe.Ty
I used git config --global mergetool.p4merge.cmd '"C:\Install Dir Has Spaces\p4merge.exe" $BASE $LOCAL $REMOTE $MERGED'Cystoid
On windows command prompt, second command failed saying wrong usage. So I executed that on git bash and it worked.Publicness
I did this in Mac terminal and now I get this error: 'p4merge: command not found'. Any suggestions?Strengthen
@Engin make sure p4merge is available in your path.Ty
@MikeGlenn, Thank you! You are the first person to share a valid config for my MINGW64 install on Windows 7. Been pulling my hair out for the past 30 minutes.Portfolio
@Michael: I had to invert the quotes like so to make it work: git config --global mergetool.p4mergetool.cmd "'C:/Program Files/Perforce/p4merge.exe' $BASE $LOCAL $REMOTE $MERGED"Rogerson
M
9

You will see here my config for DiffMerge or KDiff3.

Based on that, I would recommend for p4merge:

git config --global merge.tool merge
git config --global mergetool.merge.cmd "merge.sh \"$PWD/$LOCAL\" \"$PWD/$BASE\" \"$PWD/$REMOTE\" \"$PWD/$MERGED\""

and merge.sh being a wrapper (copied in a directory referenced by your PATH environment variable), able to take into account the case where no BASE exists.
(when a file is created in two different branches being then merged, there would be no common ancestor for that file)

#!/bin/sh

# Passing the following parameters to mergetool:
#  local base remote merge_result

alocal=$1
base=$2
remote=$3
result=$4

if [ -f $base ]
then
    p4merge.exe -dl "$base" "$alocal" "$remote" "$result" 
else
    p4merge.exe -dl "$result" "$alocal" "$remote" "$result" 
fi

You may note:

  • the use of PWD in the config of the merge
  • the use of "merge" as name of the merge.tool name (since the actual tool is called in the merge.sh script, where you can switch between any number of merge tool you want)
  • the use of double quotes around $base, $alocal, $remote, $result within the script
  • the conditional path for calling the tool, based on the existence of a "base" file.
  • the need to always have 3 files to merge as parameters (even when 'base' does not exist...)

Just tested it (it turns out, you can download and install only p4merge -- section Client/Visual Merge Tool --, even if you do not have any other P4 product installed).

With the settings describe above, MSysGit1.6.3, DOS session or Git bash session:
It just worksTM.


Update msysgit 1.7.x

Benjol mentions in the comments:

p4merge is now supported natively by msysgit.

This means you can just do:

git config --global merge.tool p4merge
# and I recommend 
git config --global mergetool.keepBackup false
Mardellmarden answered 15/5, 2009 at 6:1 Comment(6)
You've got "merge.sh twice in the second line of your first code block, but with that corrected, everything works. Thanks!Fluter
I just tried this again on a new machine. Seems to me that if you set the config from bash, the $PWD and $LOCAL variables get expanded in the config file. I had to go and edit the %USERPROFILE$\.gitconfig file manually. Maybe an error on my part, but just in case someone else has the same problem.Fluter
@Benjol: interesting, I will test it again also. Was your new machine different from your first tries? (newer Os?)Mardellmarden
@VonC, Vista, yes. Another tweak which may be worth mentioning is keepBackup = false (.orig files drive me crazy)Fluter
Note: according to the 3rd comment here, p4merge is now supported natively by msysgit. I'm not sure since which version. This means you can just do git config --global merge.tool p4merge (and I recommend git config --global mergetool.keepBackup false)Fluter
@Benjol: Thank you for the information, I have included it in the answer.Mardellmarden

© 2022 - 2024 — McMap. All rights reserved.