Three Way Merging Made Painless With P4Merge And TortoiseSVN

There is a fear of merging amongst developers (mostly juniors) and it is due to the fact that they don't merge often enough and sometimes don't use the proper tooling to make this process manager-proof.


In order to ease the pain of merging, let's use some proper merging tools.

P4Merge seems the best contender as:

  • it has 3 way-merge
  • it sports an foolproof change tracker (aka. the change 'curved area thingie')
  • it costs GBP 0.00
Let's see how to install this with tortoise svn and go through a real-world conflict.



Please find the windows 32 bit version here: http://www.perforce.com/downloads/perforce/r10.2/bin.ntx86/p4vinst.exe
And the windows 64bit version here: http://www.perforce.com/downloads/perforce/r10.2/bin.ntx64/p4vinst64.exe

When installing it, take care to only install P4Merge.

Then, you will need to setup tortoise SVN integration:




Then in the External Programs / Diff Viewer sectuin, enter these args:

C:\Program Files\Perforce\p4merge.exe %base %mine





And in the Merge Tool section:

C:\Program Files\Perforce\p4merge.exe %base %theirs %mine %merged



Now launch P4Merge and go to Edit/Preferences and select 'Ignore line ending and white space length differences'
This is fine for us as we are not whitespace-sensitive; the day we start doing Python development, we're screwed. You might also have your personal preferences with regards to the way whitespace is handled, there's no hard and fast rule here.



This is what a conflict looks like with 3-way merge in Perforce:





The layout is the following:
[Last committed version] [The version you started your work on] [Your version]
[                          Here be the result of the merge                                        ]

Notice the three seashells on the right side of the merge result. If you do not know how to use these seashells… It is quite simple really.





They represent the changes coming from the files at the top
Square= last commited version, Triangle = version you started your work on,circle=your copy.

You can click and shift click on those icons to change the content of each diff/conflict to Left/base/right and be done with your merge in minutes.

[make sure you select only one seashell when merging…]
Here is my result: I chose to use my version of the conflicted section, but to use the previous commit for the rest of the file.



Once you are satisfied with the merge, hit save then mark the file as resolved in tortoise:




Hope that helps and you got the Demolition Man reference.

No comments:

Post a Comment

Please leave your comments in English or French and I will be pleased to answer them if you have any questions.

Spammers will be walked down the plank matey. Arrr!