<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Nico Korthout</title>
    <description>The latest articles on Forem by Nico Korthout (@korthout).</description>
    <link>https://forem.com/korthout</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F911217%2Fea29c9ff-5f47-4254-93d5-22890ee2f17d.jpeg</url>
      <title>Forem: Nico Korthout</title>
      <link>https://forem.com/korthout</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/korthout"/>
    <language>en</language>
    <item>
      <title>IntelliJ-IDEA as git mergetool</title>
      <dc:creator>Nico Korthout</dc:creator>
      <pubDate>Thu, 18 Aug 2022 15:43:00 +0000</pubDate>
      <link>https://forem.com/korthout/git-mergetool-for-java-files-26jd</link>
      <guid>https://forem.com/korthout/git-mergetool-for-java-files-26jd</guid>
      <description>&lt;p&gt;The &lt;a href="https://www.git-scm.com/docs/git-mergetool"&gt;&lt;code&gt;git mergetool&lt;/code&gt;&lt;/a&gt; command allows you to resolve merge conflicts from your command line. Many merge tools are available like &lt;code&gt;vimdiff&lt;/code&gt;, which helps you resolve the conflicts without leaving your terminal. But of course, there are also merge tools available that open in a separate window to resolve the conflicts, like &lt;code&gt;opendiff&lt;/code&gt;, &lt;code&gt;meld&lt;/code&gt;, &lt;code&gt;kdiff3&lt;/code&gt;, and many more. You can run &lt;a href="https://www.git-scm.com/docs/git-mergetool#Documentation/git-mergetool.txt---tool-help"&gt;&lt;code&gt;git mergetool --tool-help&lt;/code&gt;&lt;/a&gt; to see which ones are available to you.&lt;/p&gt;

&lt;p&gt;For Java devs, IntelliJ-IDEA's 3-way merge tool provides much more comfort compared to these other merge tools. One reason is syntax highlighting, but it also seems to understand the conflicts. Often it can merge the changes automatically. Yet, I've always found it a hassle to move between my terminal and IDE.&lt;/p&gt;

&lt;p&gt;Today, all that changed when I discovered that it's possible to &lt;a href="https://www.jetbrains.com/help/idea/command-line-merge-tool.html"&gt;merge files from the command line&lt;/a&gt;. So, after reading the git manual in some more detail, I added the following to my git config (i.e. &lt;code&gt;git config --global --edit&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[merge]
    tool = idea
[mergetool "idea"]
    cmd = idea merge $LOCAL $REMOTE $BASE $MERGED
    trustExitCode = false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, when I run into conflicts, I type &lt;code&gt;git mergetool&lt;/code&gt; and IntelliJ-IDEA opens a 3-way merge window. 🚀&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Not on macOS?&lt;/strong&gt;&lt;br&gt;
The config above works for macOS, on another OS you need to adjust the configuration using the OS-specifics from the &lt;a href="https://www.jetbrains.com/help/idea/command-line-merge-tool.html"&gt;merge files from the command line&lt;/a&gt; documentation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What are those &lt;code&gt;*.orig&lt;/code&gt; files?&lt;/strong&gt;&lt;br&gt;
The merge tool creates some &lt;code&gt;*.orig&lt;/code&gt; files that stay around after resolving the conflicts. These are backup files that can be safely removed after a successful merge, or used to undo your conflict resolution. You can control these backup files with &lt;a href="https://www.git-scm.com/docs/git-mergetool#Documentation/git-mergetool.txt-mergetoolkeepBackup"&gt;&lt;code&gt;mergetool.keepBackup&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I don't regularly blog, and I'm not a native English speaker. But, I hope you found this post useful. Please reach out, if you have any tips on how I could improve. Of course, I'd also love to hear about it if you liked my post.&lt;/p&gt;

&lt;p&gt;Thanks for reading ❤️&lt;/p&gt;

</description>
      <category>todayilearned</category>
      <category>git</category>
      <category>java</category>
      <category>tooling</category>
    </item>
  </channel>
</rss>
