16

I followed Jörg W Mittag's answer in this post and have configured meld as the difftool in my git. Now I can view and compare differences of a file in different branches perfectly with this command:

git checkout branch1
git difftool branch1:file.f90 branch2:file.f90

I executed the above command, made and saved changes in meld. However, when I check the file using:

emacs file.f90

The changes I made earlier in meld are not saved at all. I don't understand why this is so; I must have not entirely correctly configured meld as the diff tool. Could any one help me with this problem? Thanks!!

Community
  • 1
  • 1
user3238512
  • 161
  • 1
  • 3

3 Answers3

10

To avoid the need to specify the filename twice, use the following:

git difftool branch -- file

This will compare branch:file with file in the working tree.

Furthermore, to diff the entire working tree with branch, use:

git difftool --dir-diff branch

As mentioned in other answers, if you need to diff branch with other_branch (some branch different from what is currently checked out), you must first check out other_branch before using the above commands.

Mark
  • 3,357
  • 30
  • 31
  • Excellent answer @Mark, this is the simplest command to perform this task. Thank you! – Gabriel Mar 07 '18 at 12:57
  • 1
    note: when I used `git difftool -t --dir-diff branch .`, and I changed files from `meld` in working directory and saved them, git (in the same directory, but a different terminal), did NOT report ANY changes with `git status`, until AFTER `meld` gets closed! (this is for git/meld inside MSYS2 shell in Windows 10) – sdbbs Jun 21 '19 at 10:27
8

Because you have explicitly given the branches of both files to be diff'ed, meld is working on temporary copies of both files. Try just giving the name of the non-checked out branch:file; this should cause meld to compare a temporary copy of the given branch:file with the checked out file of the same name.

Dipstick
  • 9,854
  • 2
  • 30
  • 30
7

In order to have your changes saved you need to compare some branch to the current working file.

In your case:

git checkout branch1
git difftool branch2:file.f90 file.f90

Alternatively, you can compare whole branch with the working dir and save your changes too. I have provided more details about that here: https://stackoverflow.com/a/22535996/2178047

Community
  • 1
  • 1
Piotr Jurkiewicz
  • 1,653
  • 21
  • 25