SECTION 2
Editor Insights
Editor Insights
Tip 9: Compare Two Files Line by Line (Diff)
In version-controlled files you will notice marks in three colors: Deleted, added, and modified lines
are highlighted in red, green, and blue, respectively.
Highlight color Difference
Red Deleted lines
Green Added lines
Blue Modified lines
Figure 4 shows the color coding in context. The color-coded bars along the editor’s left edge allow
you to track differences between your local copy and the last repository version. Navigate quickly
to modified lines by clicking the corresponding marks in the error stripe to the right.
13
© 2009 Sun Microsystems. All rights reserved.
This publication is protected by copyright. Please see page 2 for more details.
100 NetBeans
IDE Tips & Tricks
by Ruth Kusterer
FIGURE 4:
Marks representing
removed lines,
added lines, and
modified lines
SECTION 2
Editor Insights
Click the vertical bars along the left edge for a pop up with inline version control actions
(see Figure 5).
. Click the up and down arrows to navigate from one change to the next.
. Click the Revert button to roll back individual changes.
. Click the Diff Window button to compare two versions.
14
© 2009 Sun Microsystems. All rights reserved.
This publication is protected by copyright. Please see page 2 for more details.
100 NetBeans
IDE Tips & Tricks
by Ruth Kusterer
FIGURE 5:
Click the bars to
access inline
version control
actions
The built-in visual Diff Viewer highlights differences between two files (or two revisions of
one file) side by side, line by line. Again, you can tell what type of change occurred by
the color of the line. The Modern Diff Viewer in Figure 6 visualizes changes in a very
intuitive way.
SECTION 2
Editor Insights
You can even compare two files that are not under version control: The Diff Viewer works on
any pair of local files in the Projects, Files, and Favorites windows.
1. Select two similar files in the Projects (or Files or Favorites) window. Click with the Ctrl key
(Mac: Command key) pressed to select the second file.
2. Right-click one of the highlighted files, and select Tools > Diff from the context menu. This
menu item appears only when two files are selected.
3. The graphical Diff Viewer appears and gives you a detailed overview of all differences.
15
© 2009 Sun Microsystems. All rights reserved.
This publication is protected by copyright. Please see page 2 for more details.
100 NetBeans
IDE Tips & Tricks
by Ruth Kusterer
FIGURE 6:
Differences
between two files
SECTION 2
Editor Insights
See also Tip 10, Roll Back Changes in Files Not Under Version Control (Local History), and Tip 11,
Restore Deleted Files Not Under Version Control (Local History).
Tip Source
http://blogs.sun.com/roumen/entry/netbeans_quick_tip_10_diffing
Tip 10: Roll Back Changes in Files Not Under Version Control
(Local History)
One advantage of keeping your files under version control is that you can merge changes when
you work in a team. Another advantage is that you can revert to a previous revision in case a
change breaks the build. The option to roll back changes is also very handy when you work alone
and you do not use a version control system.
The IDE tracks modifications to project files that are open in the editor, and keeps a local history
of changes. Every time you save a file, a new revision is committed.
To get an overview of changes made to a file, select the file in the Projects or Files window. Right-
click the file and choose Local History > Show Local History from the context menu. The graphical
Diff Viewer opens in the main window and displays two revisions side by side. (See also Tip 9,
Compare Two Files Line by Line (Diff).)
This is how you roll back changes and restore a previous revision.
1. Select a file in the Projects or Files window.
2. Right-click the file and choose Local History > Revert to... from the context menu. The Revert
to... dialog opens.
16
© 2009 Sun Microsystems. All rights reserved.
This publication is protected by copyright. Please see page 2 for more details.
100 NetBeans
IDE Tips & Tricks
by Ruth Kusterer

Get Checkered Flag Projects: 10 Rules for Creating and Managing Projects That Win! Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.