Beyond Compare

From HaFrWiki42
Jump to navigation Jump to search

Beyond Compare is a data comparison utility. Aside from comparing files, the program is capable of doing side-by-side comparison of directories, FTP and SFTP directories, Dropbox directories, Amazon S3 directories, and archives. It is available for Windows, Mac OS, and Linux operating systems. A strength of Beyond Compare is that it can be configured as difftool and mergetool of version control systems, such as git. [1].

Rules

Minor diffs

Sometimes you don't want to see minor differences [2].

  1. Load a pair of DFM files showing the difference.
  2. Click the Session Settings button (aka Rules w/ umpire icon) or use the  Session  ⇨  Session Settings  menu item.
  3. Switch to the  Importance tab  then click the  Edit Grammar...  button to open a second dialog.
  4. Click the  New...  button below the top listbox to open a third dialog.
  5. Change the Element Name option to something like Explicit*, change the Text Matching to Explicit(Left|Top|Width|Height) = \d+ and check the Match character case and Regular expression checkboxes, then click Ok, then click Ok again in the second dialog.
  6. Explicit* should now appear in the original dialog's Grammar Elements list.
  7. Uncheck it, then change the combobox at the bottom of the dialog from Use for this view only to Update session defaults.

Git Integration

SourceTree Preferences for Diff

First of all make Beyond Compare reachable from the command line using the menu-option Beyond CompareInstall Command Line Tools which creates a symbolic link:

/usr/local/bin/bcomp

SourceTree Integration

Open SourceTree and go to menu option SourceTreePreferences and click on the Diff icon on top of the window.
Now fill the creates symbolic link into the External Diff / Merge as show on the right. Please note you have to change all input fields.

Git CLI

The Git Command Line Interface (Terminal usage) has the following commands in case of an collision:

# To See what is configured
$ git config --global --list

# Diff - Sets the requested Diff Tool
$ git config --global diff.tool bc3

# To launch a diff using Beyond Compare
$ git difftool file.ext

Beyond Compare Merge Integration

If you have the BC 4 Pro version you can create a git mergetool version for BC. The section in your global .gitconfig (full path: ~/.gitconfig). Please note I am using BC3 and have BC4.

...
[merge]
   tool = bc3
[mergetool "bc3"]
   cmd = "/usr/local/bin/bcomp" \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\"
   trustExitCode = true
...

Sublime Merge Integration

The CLI for Sublime Merge is called smerge. Make a symbolic link to /usr/local/bin/smerge.

# To See what is configured
$ git config --global --list

# Merge - Sets the requested Merge Tool
$ git config --global mergetool.smerge.cmd 'smerge mergetool "$BASE" "$LOCAL" "$REMOTE" -o "$MERGED"'
$ git config --global mergetool.smerge.trustExitCode true
$ git config --global merge.tool smerge

# To launch a merge using Sublime Merge
$ git mergetool

Merging conflict

In this example is assumed:

  • A git repo exists with instances on 2 Macs, an iMac and a MacBook.
  • A file README.md exists in the repo.
  • The status of both repo's is exactly the same on both computers
  • There are no open branches
  • In the git global config the Beyond Compare is registered as needed to be the mergetool.


Creation of the Conflict

Image 2 - BC4 Example Merge Conflict
Seq On iMac On Macbook
1.
  1. Edit file README.md on iMac and make a change.
  2. Save the changed file.
  1. Edit the same file README.md on MacBook and make another change, so do not make the same change.
  2. Save the file, Commit and Push change on MacBook.
2.
  1. Try to pull the changes from the repo.
    => Causes a merge conflict.
  2. In terminal:
    $git mergetool -- README.md
    => Popup window Image 2
 

Once Beyond Compare has completed the comparison it will show up to four panes: The left, center, and right panes at the top, with an output pane below it.
If you include a center file Beyond Compare will be able to compare both files to it and mark changes as additions, modifications, or deletions on each specific side.
Changes on the left are marked in teal and changes on the right are marked in magenta.
Overlapping changes are considered conflicts and are marked in red. (You may change the color scheme if you like.)

Conflicts

Any time there are different changes in the left and right side that are on the same lines or within two lines of each other those sections will be considered a conflict and will be colored red in the three input panes.
The output will be considered a conflict.
If the same change is made in both the left and right side it isn't considered a conflict.

Display Filters

When merging, the display filters switch from Beyond Compare's traditional ones to new ones that check the merging status of each line.
Using those filters you can limit the display to just conflicts or just changes on one side or the other.

Merging

You can navigate from difference to difference in both the input and output panes and the windows will stay synced up.
When you are positioned on a difference you can use the Take Left, Take Center, and Take Right commands to accept the changes from the left or right or keep the original from the center.
The "Take" commands are available on the toolbar, in each edit's popup menu, and as buttons next to each section in the output pane.
When it first loads, the output pane will match the center except when it can automatically take non-conflicting changes.
Each change will be colored to match the pane it originally came from.
While merging you can also edit the output pane directly, which will change the section to yellow.
If you want to revert to one of the original inputs just use the "Take" command again.

See also

top

Beyond Compare can be configured as the external difference utility in many popular VCS applications.

Reference

top

  1. Wikipedia], Beyond Compare.
  2. Stack Overflow, How do i make BC ignore certain differences while comparing.