In this section:
- Overview
- Enabling invocation of IntelliJ IDEA operations from the command line
- Comparing files using IntelliJ IDEA as a command line tool
- Merging files using IntelliJ IDEA as a command line tool
Overview
Besides using IntelliJ IDEA as an Integrated Development Environment, you can use it as a command line tool for comparing and merging files.
IntelliJ IDEA executable is platform-dependent:
- Windows:
IntelliJIdeaXX\bin\idea.exe/IdeaICXX\bin\idea.exeorIntelliJIdeaXX\bin\idea.bat/IdeaICXX\bin\idea.bat - UNIX:
IntelliJIdeaXX/bin/idea.sh/IdeaICXX/bin/idea.sh - macOS:
/Applications/IntelliJIdeaXX.app/Contents/MacOS/idea//Applications/IdeaICXX.app/Contents/MacOS/ideaTo add the launcher to your path, add its containing directory
/Applications/IntelliJ IDEA.app/Contents/MacOS.
However, for macOS and UNIX, one should create a wrapper script, since this helps avoid some drawbacks related to the usage of IntelliJ IDEA launcher.
Enabling invocation of IntelliJ IDEA operations from the command line
For macOS and UNIX platforms, we recommend creating the wrapper script, or the command line launcher to integrate IntelliJ IDEA with your shell. Then, you need to ensure that the created launcher script is within the search path of your shell.
On Windows, we recommend you add the path to IntelliJ IDEA to the environment variable Path.
Everything is done outside of IntelliJ IDEA, with the IntelliJ IDEA executable.
Note that if you have specified location of the IntelliJ IDEA executable as a Path environment
variable, the command will work no matter which directory you are currently in.
- On macOS or UNIX:
- Make sure IntelliJ IDEA is running.
- On the main menu, choose . The dialog
box Create Launcher Script opens, with the suggested path and name of the launcher
script. You can accept default, or specify your own path.
Make notice of it, as you'll need it later.
- Outside of IntelliJ IDEA, add the path and name of the launcher script to your path.
- On Windows:
- Specify the location of the IntelliJ IDEA executable in the
Pathsystem environment variable. In this case, you will be able to invoke the IntelliJ IDEA executable and other IntelliJ IDEA commands from any directory.
- Specify the location of the IntelliJ IDEA executable in the
Comparing files using IntelliJ IDEA as a command line tool
- Enable invoking IntelliJ IDEA operations from the command line.
- Type the following command at the command prompt:
where
<IntelliJ IDEA launcher(Windows) or wrapper script (MacOS or UNIX)> diff <path to file1> <path to file2>file1is your local copy,file2is the repository version.
For example:
idea diff README.md.bak README.md
Merging files using IntelliJ IDEA as a command line tool
Most often you need to merge three versions of the same file: your local version, the version in the repository or in the upstream, and the base revision, which is the origin for the two diverged versions.
- Enable invoking IntelliJ IDEA operations from the command line.
- Type the following command at the command prompt:
where
<IntelliJ IDEA launcher(Windows) or wrapper script (MacOS or UNIX)> merge <path to file1> <path to file2> <path to file3> <path to output>file1is your local copy,file2is the repository version,file3is the base revision forfile1andfile2, andoutputis the file to save the merge results in (optional).
Passing three arguments to merge tool
It is possible to pass just three arguments to the merge tool:
<path to file1> <path to file2> <path to output>.
In this case, the contents of the output will be taken as the base revision:
<IntelliJ IDEA launcher> merge <path to file1> <path to file2> <path to output> <path to output>
See the example in this
blog
to learn how to use IntelliJ IDEA diff and merge tool with Git.