# The &kompare; Handbook

## Introduction

When two or more people are working on a file and passing it back and forth between one another, it becomes difficult to see what changes have been made to a new version or copy of the file. Opening the new copy and the original, side-by-side in the application used to create it is one solution but, laborious, time consuming, and prone to error. This is where a program to show differences, diffs for short, is useful.

As would be expected, an appropriate name for such a program would be diff. As it happens, the program diff is installed on most &Linux;-based systems and is used for exactly this purpose. Developers often use diff, as a command line tool, to show differences between versions of a source code file. However, the use of diff is not limited to showing differences in code source files, it can be used on many text-based file types.

Using diff from the command line can be confusing, learning the diff command syntax and deciphering the output can bewilder most people. This is where &kompare; comes into play. Providing a graphical front-end to the diff program, the interface displays source and destination files side-by-side with all differences automatically highlighted. From this starting point, changes in one file can be sequentially applied to the other file on a selective and controlled basis. Not all changes need to be applied and if you do apply a change it can always be 'unapplied'. When all required changes have been applied they can be saved and will display as normal in the original application used to create the file.

In addition to displaying differences between a source and destination file, &kompare; can be used to create and view a special file called a 'diff'. This file captures the differences between the two sources into a single file that can be used to view and apply changes to any other copy of the file. For example, if two people are editing a document. The first person wants to make changes and send just the changes made to the second person. Normally, the first person would send a complete copy of the modified document to the second person, who would then have to compare the modified document side-by-side with unmodified version. The process for this is much like what we have described in the previous paragraphs. With &kompare; the first person would first make a local copy of the file to be modified, then make changes and compare the original and modified copy. Now using &kompare; a diff file can be created that captures only the changes made. This can be sent to the second person in place of a whole file containing the changes.

Using &kompare; the second person can view the diff file, compare it to the local copy of the document and apply the changes made by the first person. So the process can go on for many versions of the document, each person making changes, creating diffs, distributing them and applying them. This process is commonly called patching , a term taken from the program named patch which is another command line tool specifically designed for the purpose of applying diff files.

It sometimes happens that people edit a file at the same time. In this situation it is likely that people will make changes in the document at exactly the same line. This creates a problem because, without applied caution, people could be overwriting each others work as they apply the diff files they receive. Fortunately the developers of the diff and patch programs took this into consideration and so these tools will not allow such changes to be applied without manual intervention. When this state is reached, it is known as a conflict . &kompare; will display conflicts so that you can manually resolve them, deciding which changes should be applied to which file.

&kompare; is also a great program for comparison of file changes on a folder level. When used to compare folders &kompare; recursively examines subfolders and their file contents for differences. In this use case, each file where differences are found are automatically opened and listed by &kompare; where easy navigation between the various files is possible.

## Using &kompare;

### Getting Started

This section provides instructions for starting &kompare; and provides a quick tour to the &kompare; main interface.

#### Starting &kompare;

A shortcut for starting &kompare; can be found in the application menu in the Development group Development Kompare.

When &kompare; starts the first thing it does is display a dialog from which to select the files you wish to compare. Special settings for the properties of the diff and the appearance thereof can also be selected. In the file form select a source and destination source to compare. This can be any two files, folders or a &URL; and a file. Once the source and destination are selected click the Compare button.

Once &kompare; has discovered the differences it will display the main interface. When comparing two files or a URL and a file the process takes just a few seconds. However, when comparing folders with many subfolders and files, this process can take awhile.

For explanation of the options available from diff and appearance forms see configure-preferences.

#### The Main Interface

This section provides a quick tour of the main interface which is comprised of the following areas:

- Menus

- Toolbar

- Source and Destination Folders

- Source and Destination Files

- Source and Destination Line Changes

- Source and Destination Text View

- Statusbar

##### Menus

&kompare; provides a menu driven interface. Explanation to the menu items and their options is provided in command-reference.

##### Toolbar

The &kompare; toolbar provides shortcuts to the most frequently used diff and merge operations. The toolbar orientation, text positioning, icon size properties and which shortcut icons are displayed can be customized from the toolbar context menu accessed when right-clicking the toolbar with the mouse. The toolbar context menu also enables the toolbar to be hidden. If the toolbar is hidden and you wish to unhide it, select Settings Show Toolbar.

##### Source and Destination Folders

The source folder and destination folder panes display the folders in which compared files reside. When many subfolders are included in the comparison, then selecting a folder will display the first document in that folder where a difference was found between the source and destination.

##### Source and Destination Files

The source and destination file pane displays files where a difference was found for the currently selected source or destination folder. When a folder has multiple documents containing differences, all documents with a difference are listed. The selected document is displayed.

##### Source and Destination Line Changes

The source and destination line changes pane summarizes the differences found between the current source and destination documents. Selecting a record within the pane highlights and selects the difference. This is a useful way to navigate and inspect long documents with many differences.

##### Source and Destination View

The source and destination view is the main workspace of &kompare;. The contents and highlighted differences of the currently selected source and destination file are displayed here with line numbers.

##### Text View

The Text View is not displayed by default. It can be opened by selecting Settings Show Text View.

##### Statusbar

The status bar provides a summary of the current source and destination file or folder under comparison. The status bar also reports the number of changes found in the current document and counts the differences that have been applied. Furthermore, the status bar shows the overall number of documents containing differences and the current document number selected from this set. For example, a comparison run over two folders may return 1890 files with differences. The currently selected document is number 18 of 1890.

### Viewing Differences

#### Managing Screen Real-Estate

&kompare; displays the source and destination file under using equal percentage of the main interface view work area. This view area provides some features that help optimize use of screen real-estate while viewing differences, including:

Dual Scrollbars

- The most obvious feature is that scrollbars are provided both on the right and bottom edges of the view area. Using the scrollbars it is possible to move rapidly through the comparison.

Share Grip Handle

- The vertical space between the source and destination view not only makes it possible to clearly see the start and end of lines in each of the panes, but is also a grip handle that allows adjustment of percentage occupied between the source and destination views that comprise the view pane. To change pane size for one of the views, hover the mouse pointer over the grip handle then hold down the mouse button and drag left or right. Naturally, increasing the area of one pane will decrease the area available to the opposite pane within the view panel area.

  A second horizontal handle is available between the navigation panel and the source and destination view.

Docking

- The navigation panel can be undocked from the main interface by clicking the icon located top right of the panel. This opens it in a window of its own, allowing you to move it across the screen. You can even hide the navigation panel by clicking the icon. To display a hidden navigation bar again, click with the &RMB; into the menubar and select Navigation from the context menu.

Statusbar Toggle

- The status bar of the view panel can be toggled on and off by selecting Settings Show Statusbar.

#### Switching Source and Destination Views

Sometimes it can be useful to consider what the file to which differences where to be applied as the source. For example, when comparing two modified versions of a file and discovering that one file has many more modifications than the other. The file with more changes would be better as the source, since then fewer differences would need to be applied.

In this case select File Swap Source with Destination. This will switch the files displayed in all &kompare; panels.

#### Displaying Difference Statistics

For a quick overview of the differences, select File Show Statistics. This will display the Diff Statistics dialog. The following information is provided:

Old file:

- The file name of what is usually the source file or file that is unmodified.

New file:

- The file name of what is usually the destination file or file that is modified and to which differences will be applied.

Format:

- The diff format used to display the difference (see diff-format).

Number of hunks:

- The number of hunks found in the difference.

  A hunk is a chunk of lines that have been marked as different between source and destination and may include context lines depending on the diff format Lines of Context value (see diff-format).

Number of differences

- The actual number of differences found, not hunks. A hunk can contain one or more differences when the line change range and the context lines of any two or more changes overlap.

#### Navigating the Difference View

&kompare; enables rapid navigation of differences on a file level and of multiple difference files when comparing folder trees.

##### Selecting a Difference

A difference can be selected using by:

- clicking a line in the Source and Destination Line Changes pane (top right of the main window).

- clicking the highlighted difference in the View pane.

- traversing the listed differences in a comparison (see traversing-differences).

When a difference is selected it is considered to be in focus and is displayed in a brighter color that non-selected differences.

##### Traversing Differences

When a comparison finds many differences one of the best ways to approach reviewing them is to traverse the differences in a logical order, usually from top to bottom.

By default &kompare; selects the first difference found in a comparison. By selecting Difference Next Difference (&Ctrl;Down) the difference following the current selection is brought into focus. To select the difference before the current difference select Difference Previous Difference (&Ctrl;Up).

In this way it is possible to traverse differences in an orderly manner, applying and unapply differences upon review.

##### Switching Between Files

When a comparison is performed on folder level, many files may be found with differences. A complete list of the files compared with difference found is provided in the Source and Destination Folders, and Source and Destination Files panes. However, &kompare; displays differences between source and destination one comparison at time.

To switch between documents in this scenario the following options are available:

- Select the Source and Destination Folders pane to display file differences found in the Source and Destination Files pane, then select a file.

- Select Difference Previous File (&Ctrl;PgUp) or Difference Next File (&Ctrl;PgDown) to display the previous or next difference file found in the Source and Destination Files pane.

### Merging Differences

&kompare; makes the task of applying and unapplying differences as simple as point and click. Multiple apply and unapply operations can be performed on a difference as all operations are performed in memory and not written to the files on disk until the save operation is performed.

#### Applying a Difference

To apply a difference, click the highlighted difference region, then select Difference Apply Difference (Space).

#### Unapplying a Difference

To unapply a difference, click the highlighted difference region previously applied, then select Difference Unapply Difference (&Backspace;).

#### Applying All Differences

After reviewing differences between files and finding all acceptable it is possible apply them all with a single operation by selecting Difference Apply All (&Ctrl;A).

#### Unapplying All Differences

To revert all differences that have been applied previously select Difference Unapply All (&Ctrl;U).

#### Saving Changes

Once differences have been applied they can be saved by selecting File Save or File Save All.

Applied differences are saved to both the source and destination file.

### Working with Diff Files

Diff files contain only the changes made between files, or a set of files within a folder system, and may or may not contain a number of context lines before and after line changes. The sum of a line change and its context lines is known a hunk. A diff file therefore may contain multiple hunks from one or more files. When the context lines of two or more hunks overlap, they are considered a single hunk. Diff files can be used to:

- Apply the changes contained in the hunks to an original file.

- Apply the changes contained in the hunks to a file or set of original files within a folder system.

- Modified before being applied to an original file or set of original files within a folder system.

#### Creating a Diff

To create a diff file a comparison must be displayed in &kompare;. Assuming this is the case, then select File Save Diff... This will display the Diff Options dialog (see diff-settings for more information on diff formats and options). After configuring these options, click the Save button and save the diff to a file with the extension `.diff`.

#### Displaying a Diff

It is possible to display the contents of a diff file within &kompare; by opening the diff file from File Open Diff....

When viewing a diff file the hunks between the source and destination file are shown, remember that only the hunks are shown, no unmodified lines will be shown. In some cases a diff file is created with 0 lines of context. In this case only the changed lines will be displayed.

When a diff file contains hunks from multiple files &kompare; displays the hunks from each file one at a time and you can switch between files as though they were real files even though this information is only provided by the diff file contents.

#### Applying Differences in a Diff File

When viewing differences in a diff file it is possible to apply difference as you would when comparing source and destination files (see merging-differences).

#### Blending a &URL; with a Diff

In cases where a diff file is provided it is possible to compare the hunks in the diff against a file or folder. To do this select File Blend URL with Diff.... Then input the File/Folder and Diff Output paths.

When viewing differences between a source file and a diff file it is possible to apply difference as you would when comparing source and destination files (see merging-differences).

## Configuring Preferences

&kompare; enables users to set appearance preferences for difference formatting in the main interface and set behavioral properties of the diff program. The Preferences dialog can be accessed by selecting Settings Configure &kompare;....

To configure preferences for appearance select the View menu item (see view-settings).

To configure preferences for diff program properties select the Diff menu item (see diff-settings).

### View Settings

The View page in the Preferences dialog displays the Appearance and Fonts tabbed forms.

#### Appearance

The Appearance form provides controls to manage the Colors used to denote difference in the main interface, behavior of the Mouse Wheel when jogging up and down and how Tabs to Spaces conversion is managed.

&kompare; Appearance Settings &kompare; Appearance Settings

#### Color Group

To adjust color preferences used when displaying differences, click the color button to display the Select Color dialog for the following states:

Removed color

- Lines that have been removed, do not exist, between source and destination.

Changed color

- Lines that have been changed, modified, between source and destination.

Added color

- Lines that have been added between source and destination.

Applied color

- Any of the above states where the difference has been applied between source and destination.

#### Mouse Wheel

Number of lines

- The number of lines to jog the differences when turning the mouse wheel forward or backward.

#### Tabs to Spaces

Number of spaces to convert a tab character to

- Convert each tab character to n space characters.

#### Fonts

&kompare; Fonts Settings &kompare; Fonts Settings

Select the font family and size to display when displaying differences.

### Diff Settings

The Diff page in the Preferences dialog displays the Diff, Format, Options and Exclude tabbed forms. These forms can be used to configure the behavioral properties of the Diff program.

#### Diff

&kompare; Diff Settings &kompare; Diff Settings

The command used to run the diff program (default diff).

#### Format

&kompare; Format Settings &kompare; Format Settings

Adjust options for the Output Format and number of Lines of Context.

#### Output Format

Context

- The context output format adds several lines of context around the lines that differ.

Normal

- The normal output format displays differing lines without any surrounding lines of context.

Unified

- The unified output format is a variation on the context format. It is considered better than context because the output is more compact than that of context as it omits redundant context lines.

#### Lines of Context

Number of context lines

- When performing a diff with context or unified output format use this parameter to control the number of context lines included.

#### Options

&kompare; Options Settings &kompare; Options Settings

The Options tab form allows configuration of the options supported by the diff program.

#### General

Treat new files as empty

- With this option enabled diff will treat a file that only exists in one of the directories as empty in the other directory. This means that the file is compared with an empty file and because of this will appear as one big insertion or deletion.

Look for smaller changes

- Forces diff to display changes in case, punctuation, space, &etc; when checked.

Optimize for large files

- Switches diff to process files with high-speed when checked.

Ignore changes in case

- Lower and Uppercase character changes are omitted when this option is checked.

Ignore regexp

- Ignore lines matching a regular expression.

#### Whitespace

Expand tabs to spaces in output

- When checked diff outputs will converts tab characters to the number of spaces defined in the Preferences dialog View menu Tabs to Spaces option.

Ignore added or removed empty lines

- lines of zero length that differ between source and destination are ignored when this option is checked.

Ignore changes in the amount of whitespace

- White space before, after and between lines may change depending on different editors. When this option is checked such changes are ignored.

Ignore all whitespace

- when checked white space differences are completely ignored.

Ignore changes due to tab expansion

- when checked white space resulting from tab characters is ignored.

#### Exclude

The Exclude form enables use of the filter options provided by the diff program.

&kompare; Exclude Settings &kompare; Exclude Settings

#### File Pattern to Exclude

File Pattern to Exclude

- Exclude files based on wild card filtering

#### File with Filenames to Exclude

File with Filenames to Exclude

- Define the filter based on the content of an externally managed file.

## Command Reference

### Menu Items

#### The File Menu

&Ctrl;O File Open Diff...

- Displays the Open dialog.

&Ctrl;C File Compare Files...

- Displays the Compare Files or Folders dialog.

&Ctrl;B File Blend URL with Diff...

- Displays the Blend File/Folder with diff Output dialog.

&Ctrl;S File Save

- Writes applied differences to the current source and or destination file.

File Save All

- Writes applied differences to all source and or destination files.

File Save Diff...

- Displays the Diff Options dialog to define diff format and options.

F5 File Refresh Diff

- Updates the difference of the original paths. Useful if you have applied some changes, saved them and want to see what is left.

File Swap Source with Destination

- Changes source and destination.

File Show Statistics

- Displays the Display Statistics dialog.

&Ctrl;Q File Quit

- Exits &kompare;.

#### The Difference Menu

&Ctrl;U Difference Unapply All

- Unapply all differences previously applied between source and destination.

&Backspace; Difference Unapply Difference

- Revert a selected difference previously applied.

Space Difference Apply Difference

- Apply a selected difference.

&Ctrl;A Difference Apply All

- Apply all differences between source and destination.

&Ctrl;PgUp Difference Previous File

- Make the previous difference, in the list of differences, the current file in the view pane.

&Ctrl;PgDown Difference Next File

- Make the next difference, in the list of differences, the current file in the view pane.

&Ctrl;Up Difference Previous Difference

- Select the difference above the currently selected difference.

&Ctrl;Down Difference Next Difference

- Select the difference below the currently selected difference.

#### The Settings and Help Menu

&kompare; has the common &kde; Settings and Help menu items, for more information read the sections about the Settings Menu and Help Menu of the &kde; Fundamentals.

### Commandline Options

-c

- This will compare URL1 with URL2.

``kompare` `-o``

- This will open URL1 and expect it to be diff output. URL1 can also be a '-' and then it will read from standard input. Can be used for instance for ``cvs diff | kompare -o -``. Kompare will do a check to see if it can find the original file(s) and then blend the original file(s) into the diffoutput and show that in the viewer. `-n` disables the check.

``kompare` `-b``

- This will blend URL2 into URL1, URL2 is expected to be diff output and URL1 the file or folder that the diffoutput needs to be blended into.

``kompare` `-n``

- Disables the check for automatically finding the original file(s) when using '-' as URL with the `-o` option.

``kompare` `-e` `encoding``

- Use this to specify the encoding when calling it from the command line. It will default to the local encoding if not specified.

## Credits and License

&kompare;

Program copyright 2001-2004, &John.Firebaugh; &John.Firebaugh.mail; and Otto Bruggeman otto.bruggeman@home.nl

Documentation Copyright © 2007 Sean Wheller sean@inwords.co.za

&underFDL; &underGPL;
&documentation.index;