In this topic:
- Overview
- Enabling invocation of IntelliJ IDEA operations from the command line
- Comparing files using IntelliJ IDEA as a diff command line tool
- Merging files using IntelliJ IDEA as a command line tool
- Example
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: product1.exe
or product1.bat for Windows and product1.sh for Linux.
For OS X, the executable is /Applications/product1.app/Contents/OS X/....
To add the launcher to your path, add its containing directory /Applications/product1.app/Contents/OS X.
Enabling invocation of intellij idea operations from the command line
-
Using the command line commands, for example,
cdto change the directory, switch to the directory where the IntelliJ IDEA executable file is located (IntelliJ IDEA installation directory). The CMD commands, the name of the IntelliJ IDEA executable, and its default location depend on the operating system you use. See the lists of CMD commands for Windows
, OS X
,
Linux
.
-
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 command from any directory.
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.
Otherwise, you need to switch to the IntelliJ IDEA installation folder first
or specify full path to the executable.
Comparing files using intellij idea as a diff command line tool
- Enable invoking IntelliJ IDEA operations from the command line.
- Type the following command at the command line prompt:
where
<IntelliJ IDEA launcher> diff <path to file1> <path to file2>file1is your local copy,file2is the repository version.
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 line prompt:
where
<IntelliJ IDEA launcher> 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).
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>
Example
alias idiff='/Applications/product1.app/Contents/OS X/idea diff $