0

I have two files in two different branches: branch1:./path1/fileA.dat and branch2:./path2/fileB.dat.

I want to compare these files with each other and edit one of them, say fileA.dat, according to the differences shown.

If I checkout branch branch1 and use the command (as stated here):

git difftool branch1:./path1/fileA.dat branch2:./path2/fileB.dat

I am able to see the differences between these files (I use Meld as my difftool) but both are opened as temporary files so I can't really edit fileA.dat in branch1 because the changes will be lost after I close Meld.

This is not what I would have expected, since if I use a very similar command to compare the same file in these two branches:

git difftool branch1 branch2 file.dat

I can edit it and save the changes.

Am I doing something wrong here or is this just how git behaves?

Community
  • 1
  • 1
Gabriel
  • 40,504
  • 73
  • 230
  • 404

1 Answers1

1

This is not cool but it works.

First, do as you did

git difftool branch1:./path1/fileA.dat branch2:./path2/fileB.dat

Next, in Meld click 'Browse...' and select fileA.dat manually.

Then you can edit and save it.

shirakia
  • 2,369
  • 1
  • 22
  • 33
  • You're absolutely right, this works perfectly. I still wonder why `git` doesn't do this by default though. I'll leave the question open a bit more to see if somebody else has a more "git" approach, else I'll mark your answer as accepted. Thanks! – Gabriel Dec 04 '14 at 20:55
  • Thanks. I also tried to find a difftool/meld option to do this but could not find. Hope someone has a perfect answer. – shirakia Dec 04 '14 at 22:07