p4merge error [GIT]

↘锁芯ラ 提交于 2019-11-30 06:24:55

问题


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?


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/866262/p4merge-error-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!