Complete Guide to DiffMerge for Git Conflict Resolution

Struggling with Git merge conflicts? You’re not alone! Learn how to resolve conflicts visually with DiffMerge instead of staring at confusing conflict markers. This comprehensive tutorial covers installation, configuration, and practical usage for developers of all levels.


What You’ll Learn About Git Conflict Resolution

By the end of this comprehensive DiffMerge tutorial, you’ll be able to:

  • Install and configure DiffMerge for Git conflict resolution
  • Launch DiffMerge when merge conflicts occur in your Git workflow
  • Understand the DiffMerge interface and three-way merge process
  • Resolve conflicts step-by-step with visual merge tools
  • Use DiffMerge for everyday file comparisons and code reviews
  • Integrate DiffMerge into your version control workflow efficiently

Why Use DiffMerge for Git Conflict Resolution?

The Old Way: Manual Conflict Resolution

When Git encounters conflicts, it shows you something like this:

<<<<<<< HEAD
Your brilliant feature code
=======
Your teammate's amazing changes
>>>>>>> feature-branch

You have to manually delete the markers and decide which code to keep.

The New Way: Visual Resolution with DiffMerge

DiffMerge shows you:

  • Your changes (left panel)
  • Their changes (right panel)
  • The original version (center panel)
  • A visual way to pick the best parts

DiffMerge Installation & Setup

Step 1: Install DiffMerge

# Using Homebrew (easiest way)
brew install --cask diffmerge

# If you're on Apple Silicon Mac, install Rosetta first
softwareupdate --install-rosetta --agree-to-license

On Windows

Download from SourceGear’s website and run the installer.

Step 2: Configure Git

Open your terminal and run these commands:

# Tell Git to use DiffMerge for file comparisons
git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd 'diffmerge "$LOCAL" "$REMOTE"'

# Tell Git to use DiffMerge for resolving conflicts
git config --global merge.tool diffmerge
git config --global mergetool.diffmerge.cmd 'diffmerge --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE"'
git config --global mergetool.diffmerge.trustExitCode true
git config --global mergetool.keepBackup false

What these commands do:

  • First two lines set up DiffMerge for comparing files
  • Next four lines set up DiffMerge for resolving merge conflicts
  • Last line prevents Git from creating backup files (less clutter!)

How to Use DiffMerge: Real-World Scenarios

Scenario 1: Resolving Your First Git Merge Conflict

Imagine you’re working on a team project with Git version control, and you and your teammate both edited the same file. Here’s what happens when Git merge conflicts occur:

1. Git Tells You About the Conflict

When you try to merge, Git says:

$ git merge feature-branch
Auto-merging app.js
CONFLICT (content): Merge conflict in app.js
Automatic merge failed; fix conflicts and then commit.

2. Launch DiffMerge

git mergetool

3. Understanding the DiffMerge Interface for Three-Way Merge

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   LEFT PANEL    β”‚   CENTER PANEL  β”‚   RIGHT PANEL   β”‚
β”‚   (REMOTE)      β”‚   (BASE/MERGE)  β”‚   (LOCAL)       β”‚
β”‚                 β”‚                 β”‚                 β”‚
β”‚ Their changes   β”‚   Original code  β”‚   Your changes  β”‚
β”‚ (from feature)  β”‚   or your merge β”‚   (from HEAD)   β”‚
β”‚                 β”‚   result        β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • Left Panel: Shows the changes from the branch you’re merging in Git
  • Right Panel: Shows your current changes (from HEAD)
  • Center Panel: Shows the original version and becomes your final merge result

4. Resolving Conflicts

DiffMerge highlights conflicting sections in different colors. Here’s how to resolve them:

Method 1: Click the Toolbar Buttons

  • ⬅️ Choose left panel version
  • ➑️ Choose right panel version
  • ⬇️ Choose base (original) version
  • ✏️ Manually edit in center panel

Method 2: Click Individual Conflict Blocks

  • Each conflict block is highlighted
  • Click on a block to see toolbar options
  • Choose which version to keep for each block

Method 3: Manual Editing

  • Click anywhere in the center panel
  • Type or paste exactly what you want
  • Great for combining the best of both versions

5. Save and Continue

  1. Press Cmd+S (Mac) or Ctrl+S (Windows) to save
  2. Close DiffMerge
  3. Git will automatically stage the resolved file

6. Complete the Merge

git add .
git commit -m "Resolved merge conflicts with DiffMerge"

Scenario 2: Using DiffMerge for File Comparison and Code Review

Sometimes you just want to see what changed between two commits without actually merging. This is perfect for code review and understanding changes:

# Compare your current working changes with the last commit
git difftool

# Compare two specific commits to understand code evolution
git difftool HEAD~1 HEAD

# Compare your branch with the main branch before creating a pull request
git difftool origin/main HEAD

# Use DiffMerge as your default Git diff viewer for all comparisons
git config --global diff.external diffmerge

Pro Tips for Power Users

Tip 1: Skip the Prompts

Tired of Git asking β€œLaunch DiffMerge for file X? [Y/n]”?

# Auto-launch for all files
git mergetool -y

# Auto-launch for file comparisons
git difftool -y

Tip 2: Keyboard Shortcuts

  • Save: Cmd+S (Mac) / Ctrl+S (Windows)
  • Next conflict: Cmd+G (Mac) / F3 (Windows)
  • Previous conflict: Cmd+Shift+G (Mac) / Shift+F3 (Windows)
  • Choose left: Click left toolbar button
  • Choose right: Click right toolbar button

Tip 3: Handle Multiple Files

When multiple files have conflicts:

git mergetool  # Opens files one by one
git mergetool --tool-help  # See all available tools

Troubleshooting Common Issues

Issue 1: β€œdiffmerge command not found”

Solution: Make sure DiffMerge is in your system PATH

# On Mac, check if it's installed
which diffmerge

# If not found, add to ~/.zshrc or ~/.bash_profile
export PATH="/opt/homebrew/bin:$PATH"

Issue 2: DiffMerge opens but shows empty files

Solution: Check your Git configuration

# Verify configuration
git config --global --list | grep diffmerge

# Reconfigure if needed
git config --global mergetool.diffmerge.cmd 'diffmerge --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE"'

Issue 3: Changes not saved after closing DiffMerge

Solution: Make sure to save before closing

  • Always press Cmd+S/Ctrl+S before closing
  • Check that the center panel shows your intended result
  • Look for the β€œmodified” indicator in the window title

Issue 4: Merge conflicts keep reappearing

Solution: Complete the merge properly

# After resolving all conflicts:
git add .
git commit  # This completes the merge commit

When to Use DiffMerge vs Other Tools

Situation Recommended Tool Why
Simple merge conflicts DiffMerge Visual, easy to understand
Complex multi-file conflicts VS Code Built-in Git integration
Quick conflict checks Command line Fast for experienced users
Team code reviews GitHub/GitLab Collaborative features

You’re Ready to Master Git Conflicts!

Congratulations! You now know how to:

  • Install and configure DiffMerge
  • Launch it when conflicts occur
  • Navigate the interface
  • Resolve conflicts visually
  • Use it for everyday file comparisons

Quick Reference Commands

# Resolve conflicts
git mergetool

# Compare files
git difftool

# Skip prompts
git mergetool -y
git difftool -y

Additional Resources for Git Conflict Resolution


Happy merging!
May your conflicts be few and your resolutions be swift.