Adobe
Macromedia Dreamweaver 8 introduces a powerful new productivity feature that allows web developers and designers to quickly compare changes between files. To take advantage of this feature, however, you will need to download a third-party merge or "diff" utility and configure Dreamweaver to integrate with this program.
Once you have configured Dreamweaver 8, with just a few simple clicks, you will be able to compare files visually and understand the differences between two versions of a file. For any of you that have nervously uploaded or checked out files on a remote server, uncertain which changes might have been made previously, the file compare feature in Dreamweaver 8 may quickly become one of your favorite new features. In this article, I explain how to integrate a third-party file compare utility on both the Mac and Windows.
To complete this tutorial you will need to install the following software and files:
Note: FileMerge is distributed by Apple as part of the Xcode development tools which you can download for free from the Apple developer site by registering with the Apple Developer Connection (ADC). However, the latest version of Xcode requires Tiger, the latest major revision of the OSX known as Tiger (10.4).
Historically, Dreamweaver has appealed to both web designers and developers and, with few exceptions, many of the features in Dreamweaver tend to appeal to one camp or the other. Rarely, however, does a feature in the product serve the needs of both classes of user.
The file compare feature in Dreamweaver 8 is one of those rare features that has universal appeal. Whether you are tweaking CSS code for your page layout or updating your ColdFusion component code, file compare will likely become one of your favorite new tools in your web utility belt.
Difference (often referred to as just "diff") or merge utilities are very similar to simple text editors, except there are always two visible edit windows side-by-side. Each text editor typically features line numbering. When a text file is loaded in each of the two text editors, colors and other formatting are used to visually highlight differences between the files.
A couple of rules to consider when performing a file comparison include:
Some examples of when you might want to use the file compare feature include:
In my experience using Dreamweaver 8 so far, integrating file compare into my workflow has helped increase the quality of my code by reminding me to eliminate bloated code or debugging information. It's very easy to forget about snippets of code that you intended to remove at a later date. Fortunately, computers are much better at parsing code and highlighting changes than humans.
The following screen shot is an example of how the file compare utility, FileMerge, helps to visually compare modifications to an HTML file. In this case, the original file is displayed in the right-side text editor view and the updated version on the left side. At the bottom, FileMerge displays that it has detected two blocks of code that are different.
Figure 1. Two different versions of a document being compared in FileMerge
A Google search for "diff" or merge utilities reveals an impressive number of applications ranging from open source options to professional grade (around $100) options. For Windows, there are a variety of free tools available, including WinDiff, WinMerge, and ExamDiff. Though any of these will suffice, I have opted to use WinMerge for this article due to its ease of use and powerful feature set. For the Mac, I recommend the utility FileMerge provided by Apple on its Development Tools website. You can download these using the links in the Requirements section of this article.
In the next sections, I will show you how to install WinMerge for Windows and FileMerge for Mac OS X.
Follow these steps to install WinMerge on Windows. If you are a Mac OS X user, skip ahead to the section on installing FileMerge on OS X.
Click the Download WinMerge-2.2.4-Setup.exe link to download the Windows Installer.
Figure 2. Click the Download WinMerge-2.2.4-Setup.exe link to download the Windows Installer
A list of download servers appears. Find a server located near you and click the download icon.
Figure 3. Click the download icon
In the next section, you configure Dreamweaver to recognize WinMerge as your diff/merge utility.
Configuring Dreamweaver to detect the file compare application on Windows takes a few quick steps.
Select the File Compare category.
Figure 4. The File Compare category in the preferences
Click the Browse… button and specify the path of the "diff" or merge utility. See the screen shot below for the path to the EXE file.
Figure 5. The File Compare category in the preferences pointing to the file compare utility executable
The next section of this article covers installing and setting up a diff/merge utility on Mac OS X. If you are not a Mac user, skip to the section on Performing Your First File Compare.
Note: FileMerge is distributed by Apple as part of the Xcode development tools which you can download for free from the Apple developer site by registering with the Apple Developer Connection (ADC). However, the latest version of Xcode requires Tiger, the latest major revision of the OSX known as Tiger (10.4). Also note XCode is approximately 750 megabytes in size.
Open the XcodeTools.mpkg package to launch the Xcode Tools Installer application.
Figure 6. The Xcode Tools Installer application
Review the license agreement and click Continue.
Figure 7. The Xcode License agreement
The Xcode Tools must be installed on the same volume that has OSX. Select the appropriate volume and click Continue.
Figure 8. Selecting a destination for the Xcode tools.
On the installation type step, click the Customize button.
Figure 9. On the installation type step, click the Customize button
Xcode includes a great deal of software that is not necessary to run FileMerge. In fact, the default installation requires well over one gigabyte.
Figure 10. The full list of tools included with Xcode
Figure 11. Selecting only Developer Tools
Later, if you need to uninstall FileMerge for any reason, use the following steps.
Note: The current version of Xcode uses a PERL script called uninstall-devtools.pl located in the /Developer/Tools/ directory. To execute the installer, perform the following steps:
Type sudo perl /Developer/Tools/uninstall-devtools.pl (if you installed the Developers in another location, find the script and specify the appropriate location).
Figure 12. Type the command to execute the PERL script
Enter your system administrator password:
Figure 13. Entering your system administrator password
The installation process begins.
Figure 14. The prompt to enter your administrator password
In the next section, I show you how to configure Dreamweaver to recognize your diff utility.
Configuring Dreamweaver to detect the file compare application you have installed on Mac is very similar to Windows, with one major difference: Instead of pointing to the application file, you must select the command-line tool that launches the diff utility.
Click the Browse… button. On Mac, instead of browsing to the application file, Dreamweaver requires that you put it to a command-line utility that can invoke the file compare utility. In this case, browse to /usr/bin/opendiff, and click the Open button.
Figure 15. Browsing to and selecting the command-line utility that can invoke the file compare utility
A path to the opendiff command-line utility will display. Click OK to accept changes.
Figure 16. The File Compare preferences dialog box with the path to the the command-line utility that can invoke the file-compare utility
Now that you've configured Dreamweaver 8 to recognize the merge WinMerge or FileMerge utility, I will show you how to perform your first file comparison. The screen shots below are taken from WinMerge, however, FileMerge is very similar and the steps for Dreamweaver are identical.
First, imagine a specific use case or usage scenario where file compare might come into play. In this scenario, a coworker of mine—I'll call him Elvis—created a status page on our project site several months ago. Unfortunately, Elvis has since left the building and I have been asked to update the page. After defining a site in Dreamweaver that connects to the project web server, I download the page to my local machine. I've included the status.htm page in the sample files linked at the beginning of the article if you want to follow along. Unzip the file and upload status.htm to your remote server before proceeding.
Opening Elvis' original project page in Dreamweaver (status.htm), you will see a document that looks like Figure 17.
Figure 17. The project page Elvis created
Next, I will make a few of my own changes to the document to update the status page. Make these changes yourself if you are following along with the sample file, but be sure to upload your file to your remote server before making the changes because you will be comparing the two files in the next steps. Make the following changes:
The time stamp on the page will automatically change since I added it to the page using the Dreamweaver Date object (Insert > Date), and it is set to automatically update every time the page is saved. If you are following along, save the file, but don't upload it to your server.
Figure 18. The page after the changes have been made
You have created a state where the local version of the file status.htm is different than the server. But what if I wanted to know exactly what was different between the file I edited and the current version on the server before I upload it?
The first method to compare the file is to select the local file in the Files panel and select Compare with Remote. You do this by selecting the file and then right-clicking (Control-click on Mac). Then, choose the Compare with Remote menu option.
Note: This menu item is also available with the Files panel is set to remote view but the context menu indicates "Compare with Local."
Figure 19. Selecting Compare with Remote from the contextual menu in the Files panel
Once you select the Compare with Remote option, Dreamweaver downloads the remote file and makes a temporary copy of it. Next, it launches WinMerge or FileMerge and loads both the local version of status.htm and the remote version. The local version appears on the right and the remote version appears on the left. Note: If you are using WinMerge and it asks you whether you want to ignore comparing line feed endings, click Yes. Different server platforms often add special platform-specific line endings that you can ignore for the purposes of this exercise.
Note: The screen shots below are from WinMerge. If you are using FileMerge, the user interface and buttons will be similar to those shown.
Figure 20. WinMerge showing the two versions of status.htm next to each other
As you can see, the text highlighted in yellow reflects the three changes that I made in Dreamweaver. If in WinMerge, click the Next Diff toolbar button.
Figure 21. Clicking the Next Diff button to move to the next difference between the documents
After clicking the Next Diff toolbar button, WinMerge highlights the first block of text that is different between the files with red highlights. The red highlight simply indicates a block of text that is in focus.
Figure 22. WinMerge showing the next line with a difference highlighted in red
Next, click the Diff in Current Line button. This highlights the specific differences between the two files on the current line. Notice that it highlights the Word "Top" and "Very" making it very clear that I made a local change to the file.
Figure 23. Using the Diff in Current Line button to show the specific difference between that line in the two versions of the file
Using the cursor, select the second line highlighted in red and click the Diff in Current Line button. Notice that it also picked up the name change.
Figure 24. Manually selecting a line using the "Diff in Current Line" button to show the specific difference between that line in the two versions of the file
The second method for invoking the file compare feature is under the File Menu. Select File > Compare With Remote. The only difference between method 1 and 2 is the location of the menu item within the user interface.
The file compare feature can also come in handy when comparing two files locally. For those of you that do not use a version control system and simply iterate the name of the file to store file versions, you can select two files in the Files Panel by shift clicking and selecting Compare Local Files in the context menu by right-clicking.
When performing a site synchronization in Dreamweaver (Site > Synchronize Sitewide) where both the local and remote files have changed, the Synchronize preview dialog box will appear. In this dialog box, you can choose the Compare button to see (and merge) the changes into the local version and then choose to put the local version back on the remote server to resolve the conflict.
When putting a local file, you may run into an instance where you are presented with a message stating the remote version has changed. From that dialog box, you can click the Compare button to merge any remote changes into your local version before continuing to put the file. This will help ensure that you are not overwriting someone else's changes.
Now that you have successfully configured Dreamweaver to integrate with a third-party "diff" or merge utility, you might also consider exploring the various options in whatever diff tool you might be using. For instance, you might consider changing the colors that the application uses to indicate differences between the two files.
Also, if your diff utility supports merging, you might consider learning more about how to take advantage of this functionality. In some cases, you might find that you may want certain sections of code on the remote server as well as certain sections that you've added locally. Merge tools makes the process of selecting these pieces seamless.
Rob Christensen is a senior product manager on Adobe AIR. Prior to his current role, he managed a new product development framework used by many teams at Adobe and Macromedia including Dreamweaver and Flash. He also spent six years as an engineer on Dreamweaver starting with version 2. Rob's interests include web technologies, astronomy, film, travel, and exploring a variety of topics on personal blog.