Differences viewer for files
This dialog is displayed when you compare two files. To open the dialog, select two files to compare and press Control+D.
The differences viewer provides a powerful editor that enables code completion, live templates, and other features.
Diff & Merge viewer
Item | Tooltip and Shortcut | Description |
---|---|---|
/ | Previous Difference / Next Difference Shift+F7 F7 | Jump to the next or previous difference. When the last or the first difference is reached, DataGrip suggests clicking the arrow buttons or pressing F7/Shift+F7 once more and comparing other files modified locally. This behavior depends on the Go to the next file after reaching last change option in the Differences Viewer settings. |
Compare Previous/Next File Alt+ArrowLeftAlt+ArrowRight | Compare the local copy of the previous or next file with its update from the server. | |
Go To Changed File Control+N | Display all changed files in the current change set and navigate to them. This action is only available when you review changes to multiple files. | |
Jump to Source F4 | Open the selected file in the editor. The caret is placed in the same position as in the Differences Viewer. | |
Viewers | Select a viewer mode: side-by-side or unified. The side-by-side mode has two panels, the unified mode has one panel. You can edit code and perform the Accept, Append, Revert actions in both viewers. You can change text only in the right-hand part of the side-by-side viewer, or in the lower line in the unified viewer. You can edit only local versions of your files. You cannot edit files that have read-only status. | |
Whitespace | Define how the differences viewer should treat whitespaces.
| |
Highlighting mode | Select the way differences granularity is highlighted. The available options are:
| |
Collapse unchanged fragments | Collapse all the unchanged fragments in both files. The amount of non-collapsible unchanged lines is configurable in the Diff & Merge settings page. To open the Diff & Merge page, open settings by pressing Control+Alt+S and navigate to . | |
Synchronize scrolling | Click this button to scroll both differences panes simultaneously. If this button is released, each of the panes can be scrolled independently. | |
Settings | Open a list of available settings. These commands are also available from the context menu of the differences viewer gutter. | |
Include into commit Alt+I | This checkbox only appears if you invoke the Differences Viewer from the Commit Changes dialog with multiple changed files (all of which are deselected), and you explore the differences between them and hit the last difference in a file. Select this checkbox if you want to include the file you've reviewed into the commit. | |
Help F1 | Open a browser and show the corresponding help page. | |
Control+Shift+Tab | Switch between the panes of the differences viewer. The active pane has the cursor. | |
| Apply differences between panes (in case of the side-by-side viewer) or between lines (in case of the unified viewer). The chevron buttons can change their behavior:
| |
Merge actions | ||
N/A | Click this icon to invoke the list of options allowing you to compare different versions of a file to resolve a conflict. Note that Base refers to the file version that the local and the repository versions originated from (initially displayed in the middle pane), while Middle refers to the resulting version. | |
Apply All Non-Conflicting Changes | Click this button to apply all non-conflicting changes. You can also make this behavior automatic, by selecting the checkbox Automatically apply non-conflicting changes in the Diff & Merge page of the Settings dialog. | |
Apply Non-Conflicting Changes from the Left/Right Side | Click these buttons to merge non-conflicting changes from the left/right parts of the dialog. | |
Annotate with GitBlame | This option is only available from the context menu of the gutter. Use this option to explore who introduced which changes to the repository version of the file, and when. The annotations view lets you see detailed information for each line of code, such as the version from which this line originated, the ID of the user who committed this line, and the commit date. For more details on annotations, refer to VCS annotations. |
Keyboard shortcuts
Keyboard shortcut | Description |
---|---|
Control+Shift+D | Use this keyboard shortcut to show the popup menu of the most commonly used diff commands. |
Control+Shift+Tab | Use this keyboard shortcut to switch between the left and the right panes. |
Control+Z/Control+Shift+Z | Use this keyboard shortcut to undo/redo a merge operation. Conflicts will be kept in sync with the text. |
Context menu commands
This context menu is available in the middle of the editor:
Item | Description |
---|---|
Annotate | Select this check command to annotate the changes. |
Show Whitespaces | Select this check command to show whitespaces as the dots in the Differences Viewer . |
Show Line Numbers | Select this check command to show line numbers in the Differences Viewer. |
Show Indent Guides | Select this check command to have DataGrip display vertical lines in the Differences Viewer to indicate positions of indents. |
Use Soft Wraps | Select this check command to have DataGrip wrap the lines of code, when the dialog is resized. |
Highlighting level | Use this menu item to select the highlighting level in the Differences Viewer. To learn more about the level of highlighting, refer to the description of the Hector icon. |
This context menu is available in both editors:
Item | Description |
---|---|
Annotate | Select this check command to annotate the changes. |
Accept/Append | Select these commands to accept or append the lines shown in the Differences Viewer. |
Compare with Clipboard | Select this command to compare the file in the respective pane of the Differences Viewer with the . |
Switch to Three-Side Viewer | This option is available only when you are comparing two files against each other. It allows you to load a third file and add it to the comparison. |
Productivity tips
Compare two SQL queries
You can compare contents in the clipboard with selected part of an SQL query.
Copy an SQL query to the clipboard.
Select and right-click the query in the editor with which you want to compare the query in the clipboard. Without selecting the query, you compare the clipboard contents with the whole file.
From the context menu, select Compare with Clipboard.