Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using IntelliJ to diff two arbitrary files

I'm really liking the IntelliJ diff tool. I'm wondering if it is possible to use this tool to diff two arbitrary files. I.e. files NOT in an IntelliJ project. Just pick two files in the file system and diff them? What about if I want to diff two strings? In my text editor, I'd just create two new documents, paste the text in and diff them, then not save the files when done. Is this possible?

Thanks

like image 413
Greg McGuffey Avatar asked Jan 17 '13 19:01

Greg McGuffey


People also ask

How do I compare two projects in IntelliJ?

To open the dialog, select two files to compare or a file to compare its versions and press Ctrl+D .

How do I compare two branches in IntelliJ?

Select a file or a folder in the Project tool window, and choose <your_VCS> | Compare With Branch from the context menu. Choose the branch you want to compare the current file or folder version with from the dialog that opens.

How do I view two files in IntelliJ?

In the Project tool window, right-click a file and select Open in Right Split from the context menu (or press Shift+Enter ). IntelliJ IDEA will open a file in the split on the right of the editor. If there are two splits and focus is in the left split, the file will be opened in the existing right split.


2 Answers

Found this command line:

on MacOSX: (IDEA EAP 11)

/Applications/IntelliJ\ IDEA\ 11.app/Contents/MacOS/idea diff /Users/ben75/file1.txt /Users/ben75/file2.txt 

On MacOSX it can't run when IDEA (11) is open.

on Windows: (IDEA EAP 12)

"C:\Program Files (x86)\JetBrains\IntelliJ IDEA 12.0\bin\idea.exe" diff C:\Users\ben75\file1.txt C:\Users\ben75\file2.txt 

It runs even if IDEA is already open.

I have trouble when trying to compare files with no extensions (or extensions that don't match )

Directly from IDEA (EAP 12)

Not so easy, but it works...

  • File > Open... > select "file1.txt"
  • File > Open... > select "file2.txt"
  • Create a "Favorite list" and add both files to this favorite list. (to do this : ctrl+right-click on file name tab in the editor > add to favorite > select the favorite list just created - see screenshot)
  • Finally, open the "Favorites" view (Alt+2 or click on it on the left or your IDEA windows).
  • Select both files
  • Right click : "compare two files" (or ctrl+D)

add to favorites

like image 94
ben75 Avatar answered Oct 08 '22 05:10

ben75


IntelliJ Idea 13 has a feature labeled Compare with Clipboard. This feature compares the current open file with a version that you have copied into your clipboard. It's a great, easy way to compare and merge two files easily. It can also be used to compare two arbitrary blocks of code. Can't figure out why one block works and another does not? Use this feature.

This option is present under View > Compare with Clipboard. I assigned an easy to remember keyboard shortcut to give me quick access to this feature.

View > Compare with Clipboard

like image 22
Dan Torrey Avatar answered Oct 08 '22 06:10

Dan Torrey