DataGrip 2023.1 Help

Compare files, folders, and text sources

DataGrip lets you review the differences between any files, folders, text sources, or database objects, as well as between local files and their repository versions.

Compare files

DataGrip displays the differences in the Differences Viewer for Files:

Comparing files
  • New lines Green: added

  • Modified lines Blue: modified

  • Deleted lines Gray: deleted

To apply changes, use the chevron buttons — apply left and apply right.

To append changes, press Control — the apply left apply right buttons will turn into chevron button bottom right chevron button bottom left.

Compare two or three files

  • In the Files tool window, select the files you want to compare and choose Compare Files, or press Control+D.

  • Alternatively, select one file, choose Compare With from its context menu, and select a file that is outside your project.

Compare active editor with Clipboard

  • Right-click anywhere in the editor and choose Compare with Clipboard from the context menu.

Compare active editor with a project file

  1. In the Files tool window, right-click the file you want to compare with the currently opened file.

  2. Choose Compare File with Editor from the context menu.

Compare active editor with any file

If you often need to compare files that are outside your project with the active editor, or don't want to have the Files tool window open, you can use the Compare File with Editor action that lets you choose any file and compare it with the active editor.

To add this action to the editor tab's context menu:

  1. Press Control+Alt+S to open the IDE settings and select Appearance & Behavior | Menus and Toolbars.

  2. In the right pane, expand the Editor Tab Popup Menu node, select where you want to add the new action, click the Add Actions menu and select Add Action….

  3. Find and add the Compare File with Editor action under Version Control Systems | Diff & Merge.

Compare a local file with its repository version

  1. Select a modified file anywhere in the Version Control tool window.

  2. Click the Open Diff button on the toolbar or press Control+D.

Productivity tips

Assign shortcuts for 'accept' and 'append'

To assign shortcuts to the accept and append actions, open the Keymap page of the IDE settings Control+Alt+S and locate these actions under Version Control Systems | Diff & Merge.

Swap sides

When you are comparing two files, or a file with the Cliboard contents, you can swap sides by clicking the Swap Sides button on the toolbar.

Compare files from the command line

You can compare two or three files from the command line and use DataGrip as an external diff tool. Refer to Compare files from the command line for more information.

Compare folders

DataGrip lets you compare files in two folders against their file size, content, or timestamp. The differences are displayed in the Differences Viewer for Folders:

Comparing folders

The top pane lists all files in the selected folders, while the bottom pane shows the differences between two versions of the selected file (see Compare files).

Compare folders

  1. Select the folders you want to compare in the Files tool window.

  2. From the context menu, choose Compare Directories, or press Control+D.

  3. Use the following toolbar buttons to filter the list:

    • right arrow: click to display files that are present in the left folder, but are missing from the right one.

    • left arrow: click to display files that are present in the right folder, but are missing from the left one.

    • not equal sign: click to display files that are present in both folders, but whose contents, timestamp or size are different.

    • equal sign: click to display files that are present in both folders and that are identical with regard to the option selected in the Compare by dropdown.

Synchronize folders

DataGrip lets you sync the contents of two folders, or apply changes from one folder to another.

  1. For each file, click the icon in the * column until you've set an action to be taken on that file.

    • right arrow: copy the selected item from the left to the right folder. If such file already exists in the right folder, it will be overwritten.

    • left arrow: copy the selected item from the right to the left folder. If such file already exists in the left folder, it will be overwritten.

    • equal sign: no action will be performed (the two files are identical).

    • not equal sigh: no action will be performed (the two files are different).

    • close icon: remove the selected item.

  2. Do one of the following:

    • To apply the selected action to the current item, click the Synchronize Selected button the Synchronize Selected button on the toolbar or press Enter.

    • To apply the selected actions to all items, click the Synchronize All button the Synchronize All button on the toolbar.

Compare different files in two folders

Sometimes a file may be present in one folder, and another file with a similar name in the other folder (for example, VCS_library_1.4 and VCS_library_1.5). These may be versions of the same file that you want to compare. Also, there may be a situation when you think a file was renamed, but is otherwise identical to a file in another folder. DataGrip lets you compare two files, one of which is present in the right folder, and another one in the left even though such files are treated as different entities.

  1. Select the files you want to compare in the left and the right pane.

  2. Click the Compare New Files with Each Other icon Compare new files with each other button on the toolbar. The differences between the selected files will be displayed in the bottom pane.

Compare any text sources

Apart from comparing files' or folders' contents, you can open an empty Differences Viewer and paste any text or drag files into the right and left panels to compare. This can be useful, for example, if you want to compare an application's console output with the output of the same application albeit a little modified.

  1. Press Control+Shift+A and start typing to locate the Open Blank Diff Window action.

  2. Paste any text you want to compare in the left and right panels.

    Right-click either left or right panel and select Switch to Three-Side Viewer to compare any three text sources.

Productivity tips

Assign a shortcut for the 'Open Blank Diff' action

On the Keymap page of the IDE settings Control+Alt+S, locate this action under Version Control Systems | Diff & Merge.

Swap sides

You can swap sides in the Diff Viewer by pressing the swap sides icon on the toolbar.

Open Diff in a separate window

By default, Differences Viewer opens in an editor tab. You can configure the settings to open the viewer in a separate window instead. On the Advanced Settings page of the IDE settings Control+Alt+S, disable the Open Diff as Editor Tab option.

Compare via an external diff tool

You can set up and launch an external diff tool to compare your files and changes right from DataGrip. Make sure to install the necessary diff tool on your machine beforehand.

Configure an external diff tool

  1. Press Control+Alt+S to open the IDE settings and select Tools | Diff & Merge | External Diff Tools.

  2. Select the Enable external tools option.

    Enable external diff tools
  3. In the Configure external tools section, click App general add.

  4. In the Add An External Tool dialog that opens, fill in the following details:

    • Tool group: select Diff tool from the list.

    • Program path: specify the path to the diff tool executable in your system.

    • Argument pattern: if necessary, adjust the pattern for displaying changes, where:

      • %1 - local changes

      • %2 - content from the remote server

      • %3 - the current version without local changes

    Add kdiff3 as an external diff tool

    Click Test Diff or Test Three-Side Diff to check that the external diff tool launches from DataGrip successfully.

  5. Click OK to save the changes.

Launch an external diff tool from DataGrip

  • When examining differences in Differences Viewer, click App general external tools to have DataGrip launch the configured external diff tool.

Last modified: 18 April 2023