How to use Meld as a difftool for Git?

abbazs

abbazs

Posted on May 31, 2023

How to use Meld as a difftool for Git?

Meld is a graphical tool that lets you compare and merge files or directories. You can use it as a difftool for Git to visually inspect the changes in your Git repositories. Here are the steps to set up and use Meld as a difftool for Git:

  1. Check if you have Meld installed on your system by running this command in a terminal or command prompt:
   meld --version
Enter fullscreen mode Exit fullscreen mode

If you see the version information, you are good to go. Skip to step 3. If not, follow the next step to install Meld.

  1. Install Meld on your system depending on your operating system:
  • For Ubuntu or Debian-based systems, run:

     sudo apt-get install meld
    
  • For Fedora or CentOS-based systems, run:

     sudo dnf install meld
    
  • For macOS systems with Homebrew, run:

     brew install meld
    
  • For Windows systems, download the installer from https://meldmerge.org/ and follow the instructions.

  1. Create or edit your global .gitconfig file by running this command in a terminal or command prompt:
   git config --global --edit
Enter fullscreen mode Exit fullscreen mode

This will open the file in your default text editor.

  1. Add these lines to the file to tell Git to use Meld as the difftool:
   [diff]
       tool = meld
   [difftool]
       prompt = false
   [difftool "meld"]
       cmd = meld "$LOCAL" "$REMOTE"
Enter fullscreen mode Exit fullscreen mode

These lines set Meld as the difftool and provide the command for launching it with the right file parameters. The prompt = false line stops Git from asking you every time if you want to use Meld or not. Don't worry, this won't affect the normal git diff command which will still work as usual.

  1. Save and close the file.

  2. Check that the file is updated correctly by running this command:

   git config --global --list
Enter fullscreen mode Exit fullscreen mode

You should see the configuration options you added for Meld in the list.

  1. You are ready to use Meld as the difftool by running git difftool in your Git repositories. For example, to compare two commits, run:

    git difftool <commit> <commit>
    

    Git will open Meld and show you the differences between the commits for easy comparison.

You can use git difftool just like git diff. For example, to compare a file in different branches or commits, run:

```
git difftool <BRANCH_NAME> file_name
git difftool <COMMIT_HASH> file_name
git difftool <COMMIT_HASH_1> <COMMIT_HASH_2> file_name
```
Enter fullscreen mode Exit fullscreen mode

Meld will display the diff in a graphical interface with two panes. The order of the panes depends on the order of $LOCAL and $REMOTE in the cmd line. If you want to swap them, just change the order like this:

cmd = meld "$REMOTE" "$LOCAL"
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
abbazs
abbazs

Posted on May 31, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related