Siebel EAI >  Tortoise SVN Tutorial

Tortoise SVN Tutorial 

A diff/merge tool for Windows
Version 1.10
Stefan Küng
Lübbe Onken
Simon Large

Source Code
TortoiseSVN is under the GPL license. That means you can get the whole source code and build the program yourself.

Overview
TortoiseMerge is a free/open-source application. It lets you see differences in text files, merge those changes and even review and apply unified diff files, often called patches.

While working on text files, e.g. source files in your favourite programming language, or html/xml files for your documentation or website, you will often have a situation where you need to compare different versions of those files. Sometimes you get a different version from someone else, sometimes you just want to see the changes you've made.

If you're working with a version control system (e.g. Subversion) then you sometimes get conflicts when you update your working copy. This happens if someone else changed the same parts of the file you're currently working on as you did. Then you have to resolve those conflicts manually. This is where TortoiseMerge can help you.

The following diagram shows you the relationships between the files involved in a conflict:

SVN File Conflict


Basic Concepts


Viewing the difference between two files and merging changes into one of them, or removing unwanted changes.

Editing conflicts between local changes and changes in the Subversion repository following an update.

Applying patch files and reviewing them.

Viewing and Merging Differences

In this mode you are comparing two files. The file in the left pane is considered to be the original file (sometimes referred to as Theirs, and the file in the right pane is the modified file (sometimes referred to as Mine.

You can make simple line-based changes to the file in the right pane which include:

Reverting changed lines back to the text shown in the left pane.

Using a combination of both blocks, either Theirs before Mine or Mine before Theirs.

You can also edit the file in the right pane just as you would in a text editor. Such lines are marked using a pencil icon. Please note that if you want to make any of the line/block-based changes described above, it is better to do those first since once you start editing the file yourself it becomes impossible for TortoiseMerge to keep track of the relationship to the original files.


Editing Conflicts
This is sometimes referred to as a three-way merge, and is shown in three panes. However there are actually four files involved. The file which is not shown is the common base file, the last common ancestor of the two files which are now in conflict. The relationships between the three files are explained in the diagram below:

Figure 2.1. File Conflict
SVN File Conflict

File Conflict

The base file represents the oldest version of a file, from where You and They start making changes. Mine represents the base file with all the changes you made, and Theirs is the file with all the changes someone else made to the file. The left pane shows the changes in Theirs relative to the base file and the right pane shows the changes in Mine relative to the base file. The bottom pane is the output file which is where you are trying to resolve the conflicts.

In conflict resolution view, you can choose to use blocks from Mine or Theirs or both. But in this case, the changes are shown in the bottom pane.

Applying Patches
A patch file is a Subversion unified diff file, which contains the information required to apply changes to a set of files. The patch may have been supplied by another developer so that you can see changes he has made and possibly commit them to the repository. Or it may have been generated internally by TortoiseSVN when comparing two folders. This happens when you compare a repository revision with your working copy folder, or if you compare two different repository revisions, or if you compare two different repository paths.

 

In either case TortoiseMerge will show a small window listing the files included in the patch. By double clicking on one of these files you fetch the relevant file and apply the changes. The left pane shows the original file content and the right pane shows it after the patch is applied.

You can edit the file in the right pane exactly as you would in compare/edit mode.

Viewing Modes
TortoiseMerge has three main viewing modes: one-pane, two-pane and three-pane view. One/two-pane view is used to view changes and three-pane view is used to resolve conflicts.

Viewing / Merging
SVN One pane view

One Pane View

Two Pane View

The two pane view has some features which are not available in the one pane view:

Changes inside the modified lines are shown in different colors. Added string parts are shown with a lighter color, but you can of course configure the colors used here. Removed parts are indicated with a dark brown vertical line in the string. Check out the screenshot above to see how this works.

Code reorganization usually means a lot of changes in whitespaces (space, tab, newlines) but no actual code change. For example, you split up a very long line into several lines, or you sometimes compact several lines together into one.

Such changes are marked with a white circle symbol on the left side of the views. If you see such a white circle, you know immediately that no real code change is there and you don't have to check the changed block further.

Hand editing of the file in the right pane is possible in two-pane view. Such changes are marked with a pencil symbol. Hand editing of the file in the left pane is also possible, only when Enable Edit is pressed when the left pane is active.

If you want to compare/merge three files, TortoiseMerge will show you the differences in a three pane view. This view is also used if you need to resolve conflicted files.

SVN 3 Pane View

Three Pane View

The left pane shows you the differences between Their file and the Base file, while the right pane shows you the differences between Mine file and the Base file. The bottom pane shows you the result of merging Base, Mine and Theirs with possible conflicts.

If you hover the mouse over the pane title, a tooltip will show the filenames used for the diff in each pane.

Hand editing of the file in the left pane or right pane is also possible, only when Enable Edit is pressed when that pane is active.

Applying Patches
After TortoiseMerge parses the patch file it will show you a small window with all the files which have changes according to the patch file.

SVN Files to Patch

Patch File List

If the filename is shown in black, then the patch can be applied without any problems. That means the file is not outdated according to the patch. However, if the filename is shown in red, then the patch can't get applied directly because you already changed that file.

The patch file window has a context menu which allows you to preview the effect of the patch on the current file (apply without saving), to apply and save the changes for the selected file, or to apply and save changes to all files in the list. The double click action is to preview.

 

Buttons and Other Controls
Depending on your setting, you either see a toolbar or a ribbon with many buttons. The buttons all show a tooltip explaining their function when you hover the mouse pointer over them.

 

On the left side of the window is a locator bar. This provides a quick visual reference as to where the changes lie within the file. The bar has three columns. The left column refers to the left pane, the right column to the right pane, and the centre column to the bottom pane (if present). In one-pane view only the left column is used. The locator bar can also be used as a scroll bar to scroll all the windows simultaneously.

If you double click on a word then every occurrence of that word will be highlighted throughout the document, both in the main panes and the locator bar. Double click on the word again to remove the highlighting.

If you click in the left margin, or if you triple click within a line, that whole line will be selected.

Below the bottom window is the status bar. This shows the number of lines added and deleted in Theirs and Mine, and the number of unresolved conflicts remaining.

The status bar also contains combo box controls which indicate how the files are handled and treated:

Encoding
The encoding specifies how the characters in the views are loaded/saved and shown. The most common encoding in English is ASCII (which means the local encoding of the OS language), but you can change this to be UTF8, UTF16LE, UTF16BE, UTF32LE and UTF32BE, both with or without a byte order mark (BOM).

Line Endings
The most common line endings on Windows is CRLF, but you can change the line endings to whatever you like. Note that if you change the line endings, then all line endings in the whole file will change, even if when loaded the line endings were not all the same.

Tabs
The option at the top of the combo box menu indicates whether tabs or spaces are inserted when you press the tab key. The smart tab char option if enabled uses an algorithm to determine whether one or the other is best used.

The tab size specifies how many space chars are inserted when editing and pressing the tab char, or how many chars the next word is indented when a tab char is encountered.

Line Status Icons list

Line Status Icons

 

Merging / Editing Conflicts
TortoiseMerge not only shows you the differences between files but also lets you resolve conflicts or apply changes.

If you're in two pane view, then you can only edit the file in the right pane (Mine). To apply changes made in the left file (Theirs), right click on the changed lines and select Context Menu → Use text block from 'theirs' . Then the changes from the left file are added to the right file.

 

Sometimes you actually want both text blocks, and the context menu also offers you Context Menu → Use both text blocks (this one first) and Context Menu → Use both text blocks (this one last).

You can also edit the output file just as you would in a text editor. Such lines are marked using a pencil icon. Please note that if you want to make any of the line/block-based changes described above, it is better to do those first since once you start editing the file yourself it becomes impossible for TortoiseMerge to keep track of the relationship to the original files.

If you're in three pane view (sometimes called merge view) you can only edit the file in the bottom view (Merged). As in two pane view, you can right click on conflicted lines and either select Context Menu → Use text block from 'theirs' or Context Menu → Use text block from 'mine' . In addition, if you want both blocks, you can select Context Menu → Use text block from 'mine' before 'theirs' or Context Menu → Use text block from 'theirs' before 'mine' . According to the command you've selected, the changes are used in the resulting Merged file.

Sometimes a file will be marked as conflicted in Subversion, yet when you view it using TortoiseMerge there are no conflicts shown. This may be due to the whitespace handling you have chosen. If you choose to ignore line-endings or whitespace changes, those lines will be marked using the Conflict-Ignored icon. To resolve the conflict you still need to pick which version you want to use.

Important
Note that if you use TortoiseMerge on the same files again, any changes to your working copy, whether in TortoiseMerge, or by hand-editing, will be discarded and the file will appear as it did when conflict-editing first started.


Open Files
When you start TortoiseMerge without any command line switches then you have to open the files manually, using File → Open.

SVN Open Dialogue

The Open Dialog

The first thing you have to do is to decide whether you just want to compare/merge files, or whether you want to apply a patch file. Depending on what you choose, the corresponding edit boxes and browse buttons are activated.

Viewing / Merging
If you want to compare / merge files you have to set at least two of the three possible paths for Base, Mine and Theirs. If you select only two files, then TortoiseMerge will show you the differences between those two files, either in a two pane view or in a one pane view.

 

If you want to merge three files, TortoiseMerge will show you the differences in a three pane view. This view is generally used if you need to resolve conflicted files. The output file is not named in this case and you will have to use the File → Save As.... to save the results.

Applying Patches
If you want to apply a patch file you have to set both the path to the patch file itself and the path to the folder where the patch file should be applied.


Settings
Main Settings Page

Main Settings Page

Most of the options here are self-explanatory, but a few points need clarifying.

Backup original file renames the original file in the WC to filename.bak before saving the modified version.

Default to UTF-8 encoding when set, ANSI files are loaded as UTF-8 encoded and saved as such when edited.

Max line length for inline diffs TortoiseMerge can get slow when showing inline diffs for very long lines. Because of that only lines that are shorter than 3000 chars are shown with inline diffs. You can change this value here.

Ignore line endings hides changes which are due solely to difference in line-end style.

Ignore case changes hides changes which are due solely to case changes within the text. This can be useful with apps such as Visual Basic, which changes case in variables without warning.

Colour Settings Page

 
Color Settings Page

This dialog allows you to select the background color coding used to highlight the different line changes.

Normal
All lines which are unchanged, or where changes are hidden.
Added
Lines which have been added.
Removed
Lines which have been deleted.
Modified
Lines which have relatively small changes, and are shown using inline diff. This colour is used for the unchanged portion of the line content. Changed portions will be shown using the inline added and deleted colours described below. If Colour code in-line changes is not enabled, this colour will not be used and changed lines will always be shown as replacements.
Conflicted
Where the same line has been changed in both files.
Conflict resolved
Where the same line has been changed in both files, and you have now selected which version should be used.
Empty
Where lines have been added in the opposite pane, and no such line existed in this pane.
Inline added text
When inline diffs are shown, added text is shown in this colour.
Inline removed text
When inline diffs are shown, deleted text is shown in this colour.
Misc whitespaces
Characters used to indicate Whitespace are shown in a different colour from normal text.