6

I'm looking for a Linux-based tool for 3 way merging/resolving, using Perforce. I'm familiar with vim/vimdiff, but I don't know how/if they can be used for 3 way merging. In either case, do let me know what, according to you, is the best merge/resolve tool on Linux.

For clarity, let me add that I'd prefer a tool which doesn't requires X server i.e. can be used through putty.

TCSGrad
  • 11,898
  • 14
  • 49
  • 70

4 Answers4

4

I guess you are talking about resolving files in three way diff tool. The different versions are,

  • ORIGINAL
  • THEIRS
  • YOURS

Now, to do that a little setup is needed in linux. I have a .p4config file that defines my preferable diff tool.

P4CLIENT=mywork
P4DIFF=diff -u
P4EDITOR=vi
P4IGNORE=.p4ignore

Here P4DIFF is set to diff -u. To make the whole thing work the .p4config file needs to be plugged to perforce by environment variable.

export P4CONFIG=.p4config

Now it is the sweet-spot. We need to actually do the resolve by p4 resolve command.

p4 resolve /path/to/mysource.h

As soon as we do that, it shows that there is conflict as someone modified the original version we were working. So it prompts for our action.

/path/to/mysource.h - merging //stream/version/path/to/mysource.h#2
Diff chunks: 13 yours + 2 theirs + 0 both + 1 conflicting
Accept(a) Edit(e) Diff(d) Merge (m) Skip(s) Help(?) e: d

We can see the diff by pressing d.

--- /path/to/mysource.h 2016-09-28 18:34:54.918709150 -0400
+++ /path/to/tmp.6365.102   2016-09-29 11:05:32.228946564 -0400
@@ -16,6 +16,7 @@
we are same in all branches
same as everywhere 
+ added line
more same

@@ -28,7 +29,12 @@
here you go the conflict
+>>>> ORIGINAL //stream/version/path/to/mysource.h#1
+ the original line is here
+==== THEIRS //stream/version/path/to/mysource.h#2
+ their line is here
+==== YOURS /path/to/mysource.h
my line is here
+<<<<
Accept(a) Edit(e) Diff(d) Merge (m) Skip(s) Help(?) e: e

Now it is possible to fix this typing e. It will open an editor where we can compare the different versions in between the +==== lines and +<<<< lines.

Once we are done with editing we can accept by typing a.

Accept(a) Edit(e) Diff(d) Merge (m) Skip(s) Help(?) ae: a

The whole process can be done from remote command/shell window. So there is no X-server is needed.

KRoy
  • 1,290
  • 14
  • 10
  • 1
    Here is an way that vimdiff can be used for git http://vim.wikia.com/wiki/A_better_Vimdiff_Git_mergetool . For perforce set, P4MERGE=vimdiff . Here is more https://gist.github.com/tony4d/3454372 – KRoy Feb 28 '17 at 16:41
4

I prefer meld It is powerful yet lightweight and has no KDE deps as Kdiff3 does. Look at official homepage

maverik
  • 5,508
  • 3
  • 35
  • 55
  • 1
    Does it require X server ? I'd prefer to have a tool I can use through putty .... – TCSGrad Mar 14 '11 at 08:45
  • Yes, it require X. I don't actually know the CLI based 3-way diff/merge solutions besides vimdiff which can handle 3 files (see man): `vimdiff file0 file1 fil2` – maverik Mar 14 '11 at 08:59
4

If you're dead set on not using an X client, try taking a look at emacs' ediff. That works in text mode (though it's easier in X).

Dominic Mitchell
  • 11,861
  • 4
  • 29
  • 30
1

I have something called diff3, which has a merge option. I'm not sure where it came from and I have not used it. diff3 -m file1 file2 file3. Take it for what it's worth.

Btw, I'm running OpenSuSE 11.2, if that helps.

Chance
  • 2,653
  • 2
  • 26
  • 33