beyond compare with `git difftool --dir-diff` -- Hitting an issue with sym-links
Asked Answered
C

2

32

Setup a new git repo and add some files:

[Feb-09 18:35][Desktop]$ mkdir exampleForStackOverflow
[Feb-09 18:35][Desktop]$ cd exampleForStackOverflow/

[Feb-09 18:35][exampleForStackOverflow]$ git init
Initialized empty Git repository in ~/Desktop/exampleForStackOverflow/.git/

[Feb-09 18:35][exampleForStackOverflow]$ touch foo.txt
[Feb-09 18:35][exampleForStackOverflow]$ touch bar.txt
[Feb-09 18:35][exampleForStackOverflow]$ touch baz.txt

[Feb-09 18:36][exampleForStackOverflow]$ git add *

[Feb-09 18:36][exampleForStackOverflow]$ git commit -m "Create files"
[master (root-commit) 42bfa60] Create files
 3 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 bar.txt
 create mode 100644 baz.txt
 create mode 100644 foo.txt

Modify the files:

[Feb-09 18:37][exampleForStackOverflow]$ echo "Foo" > foo.txt 
[Feb-09 18:37][exampleForStackOverflow]$ echo "Bar" > bar.txt 
[Feb-09 18:37][exampleForStackOverflow]$ echo "Baz" > baz.txt

Current status:

[Feb-09 18:38][exampleForStackOverflow]$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   bar.txt
    modified:   baz.txt
    modified:   foo.txt

no changes added to commit (use "git add" and/or "git commit -a")

Current diff:

[Feb-09 18:38][exampleForStackOverflow]$ git diff
diff --git a/bar.txt b/bar.txt
index e69de29..ebd7525 100644
--- a/bar.txt
+++ b/bar.txt
@@ -0,0 +1 @@
+Bar
diff --git a/baz.txt b/baz.txt
index e69de29..a688182 100644
--- a/baz.txt
+++ b/baz.txt
@@ -0,0 +1 @@
+Baz
diff --git a/foo.txt b/foo.txt
index e69de29..bc56c4d 100644
--- a/foo.txt
+++ b/foo.txt
@@ -0,0 +1 @@
+Foo

Now with bcompare I get the following:

[Feb-09 18:38][exampleForStackOverflow]$ git difftool --dir-diff

enter image description here

This is clearly not the expected behaviour. The files do not align so differences cannot be seen.


I am running:

[Feb-09 18:44][exampleForStackOverflow]$ git --version
git version 2.7.1

[Feb-09 18:44][exampleForStackOverflow]$ cat /etc/redhat-release 
CentOS release 6.6 (Final)

Beyond Compare: Version 4.1.3 (build 20814)

git config:

[Feb-09 18:45][exampleForStackOverflow]$ git config --list
color.ui=true
user.name=FOO
[email protected]
log.decorate=full
diff.tool=bc3
difftool.bc3=trustExitCode
merge.tool=bc3
mergetool.bc3=trustExitCode
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true

Question: (From Ismail Badawi) What does this have to do with symlinks?

Answer: Sorry the screenshot isn't extremely clear but the files on the right hand side are symlinks. See below:

[Feb-09 18:52][exampleForStackOverflow]$ cd /tmp/git-difftool.RWDqE/right
[Feb-09 18:52][right]$ ll
total 0
lrwxrwxrwx 1 BAZ BAZ_g 54 Feb  9 18:51 bar.txt -> /home/BAZ/Desktop/exampleForStackOverflow/bar.txt
lrwxrwxrwx 1 BAZ BAZ_g 54 Feb  9 18:51 baz.txt -> /home/BAZ/Desktop/exampleForStackOverflow/baz.txt
lrwxrwxrwx 1 BAZ BAZ_g 54 Feb  9 18:51 foo.txt -> /home/BAZ/Desktop/exampleForStackOverflow/foo.txt
Conrado answered 9/2, 2016 at 23:48 Comment(2)
What does this have to do with symlinks?Setser
@IsmailBadawi: UpdatedConrado
S
56

In addition to sixtyfootersdude's suggestion, another option is to make Beyond Compare follow symbolic links. This will align symlinks with files of the same name.

In the Folder Compare, click the Rules toolbar button (referee icon). Go to the Handling tab. Check Follow symbolic links.

To make this affect all new sessions, change the dropdown at the bottom of the dialog from Use for this view only to Also update session defaults before you click OK.


Snapshots:

enter image description here

enter image description here

Soke answered 10/2, 2016 at 15:56 Comment(3)
Nice. I like this solution even better. I looked for this option in Bcompare but couldn't find it. Since you work for scooter: Why isn't' the rules button available from the top menu? Maybe under tools?Conrado
From the top menu on Windows or Linux, open Session > Session Settings, then go to the Comparison tab to get to the same place as the Rules toolbar button. On Mac the menu item is Beyond Compare > Session Settings.Soke
Thanks! Also remember to pick "Ignore Folder Structure" if you want a plain list of all changed files.Coates
C
25

Using this will work:

git difftool --dir-diff --no-symlinks

From the git doc:

--[no-]symlinks

git difftool's default behavior is create symlinks to the working tree when run in --dir-diff mode and the right-hand side of the comparison yields the same content as the file in the working tree.

Specifying --no-symlinks instructs git difftool to create copies instead. --no-symlinks is the default on Windows.

Conrado answered 10/2, 2016 at 0:10 Comment(1)
This works well for viewing the differences. But beware that this method does not allow you to edit your files (as they're only temporary copies).Marasmus

© 2022 - 2024 — McMap. All rights reserved.