23

I would like to compare 2 files in intellij. Both files are not part of a specific project.

Is there a way to do so?

I am running Intellij 15 and 16.

galusben
  • 5,948
  • 6
  • 33
  • 52
  • It's really a lot easier if the 2 files fall under the project strucuture - then control-click to select both files and control-d does the trick. Otherwise... why not use an external tool, for example on windows I use "Beyond Compare" ? – vikingsteve Jun 09 '16 at 13:22
  • 2
    I know I can use an external tool, but, I prefer using Intellij if possible – galusben Jun 09 '16 at 13:45
  • You can always just drag them into the project structure, do the compare, and remove them afterwards. Sorry but I'm not aware of the exact feature you want... although you could always write a plugin to do it, if you can learn about the virtual file system (vfs). – vikingsteve Jun 09 '16 at 14:24
  • 1
    Possible duplicate of [Using IntelliJ to diff to arbitrary files](https://stackoverflow.com/questions/14386488/using-intellij-to-diff-to-arbitrary-files) – RamValli Sep 26 '17 at 07:15

7 Answers7

24

The following works for me in IntelliJ IDEA Ultimate 14.1.7 on Windows:

  1. Open the first file in the IDE (either by dragging from Windows Explorer into the window, or by File / Open).
  2. In the view menu, choose "Compare With…"
  3. In the "Select Path" dialog that appears, select the second file (either directly, or by dragging from Windows Explorer into the dialog).

It then opens up in the traditional file comparison pane. If you try to edit one of the files, it presents the usual "Are you sure you want to edit a file that's not in your project" dialog, which one can accept if that's what one is trying to do.

10

You can use the "compare with clipboard" feature.

From https://www.jetbrains.com/help/idea/2016.1/comparing-files.html#clipboard:

Comparing a File in the Editor with the Clipboard Contents

  1. Open the desired file in the editor.
  2. Right-click the editor pane and choose Compare with Clipboard on the context menu.
  3. View and manage differences in the Differences Viewer for Files.
IppX
  • 305
  • 1
  • 13
  • This is good, and I up-voted. But, is there anything that will let you edit the 2 files? – galusben Jun 08 '16 at 18:54
  • Well you can always open/diff/edit files that are outside of your project. You'll just have a dialog asking you if you really want to edit the file that is not in your project. – IppX Jun 09 '16 at 13:25
  • but after doing so, there is no way to compare those 2 files in a way that you can edit the 2 files. If you know a way please show. – galusben Jun 09 '16 at 13:43
  • The following worked for me (in idea 14): open the external file, right click on the project file I want it to compare to -> Compare ..., the Differences Viewer opens with both files side by side and I can edit them. – IppX Jun 09 '16 at 15:27
9

You can use intellij to compare 2 files/clipboard/blank text etc

Use command Shift+Command+A to search Actions

  1. Type "Open Blank Diff Window" to compare random text
  2. type diff for all diff options.
Bharat Pahalwani
  • 1,404
  • 3
  • 25
  • 40
  • From an open blank diff window, right click and choose "Switch to a File..." in each pane of the diff window to browse for a file to choose. (Intellij IDEA 2021.2.2) In my version of IDEA, Actions is also reachable via Help > Find Action... – jmmygoggle Jan 21 '22 at 19:35
4

I use this on the command line (with IntelliJ IDEA CE on a Mac):

/Applications/IntelliJ\ IDEA\ CE.app/Contents/MacOS/idea diff ~/Junk/file1.txt ~/Junk/file2.txt
Jonathan Aquino
  • 343
  • 2
  • 8
0

Window > Editor Tabs > Split Vertically

Is that what you're looking for? It's what I was looking for.

ArtOfWarfare
  • 20,617
  • 19
  • 137
  • 193
0

Worked for me on Mac OS High Sierra + IntelliJ IDEA 2018.3

- File -> Open
- Select file 1
- View -> Compare with ...
- Select file 2
user674669
  • 10,681
  • 15
  • 72
  • 105
0

To use intelli's difference comparison between 2 different files, you can use the Compare With (Right click the file in Project window). There is also an option to Compare File in Editor. To use that option, ensure one file is open and selected, then right click the 2nd file, clicking Compare File in Editor

right click menu

Ben Butterworth
  • 22,056
  • 10
  • 114
  • 167
  • Using the Project window doesn't meet the original "not part of an open project" requirement, but this approach can be used if you've drag+dropped a folder containing files to a Favorites list, or manually opened a non-project file and added it to a Favorites list. (Intellij IDEA 2021.2.2) – jmmygoggle Jan 21 '22 at 19:27