six*_*ude 21 git diff beyondcompare
设置一个新的git repo并添加一些文件:
[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
Run Code Online (Sandbox Code Playgroud)
修改文件:
[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
Run Code Online (Sandbox Code Playgroud)
当前状态:
[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")
Run Code Online (Sandbox Code Playgroud)
当前差异:
[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
Run Code Online (Sandbox Code Playgroud)
现在使用bcompare我得到以下内容:
[Feb-09 18:38][exampleForStackOverflow]$ git difftool --dir-diff
Run Code Online (Sandbox Code Playgroud)
这显然不是预期的行为.文件没有对齐,因此无法看到差异.
我在跑步:
[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)
Run Code Online (Sandbox Code Playgroud)
超越比较: Version 4.1.3 (build 20814)
git配置:
[Feb-09 18:45][exampleForStackOverflow]$ git config --list
color.ui=true
user.name=FOO
user.email=BAR@BAZ.com
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
Run Code Online (Sandbox Code Playgroud)
问题:(来自Ismail Badawi)这与符号链接有什么关系?
答:抱歉屏幕截图不是很清晰,但右侧的文件是符号链接.见下文:
[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
Run Code Online (Sandbox Code Playgroud)
Chr*_*edy 36
除了sixtyfootersdude的建议之外,另一个选择是使Beyond Compare遵循符号链接.这将使符号链接与同名文件对齐.
在" 文件夹比较"中,单击" 规则"工具栏按钮(裁判图标).转到处理选项卡.检查遵循符号链接.
要使此操作影响所有新会话,请将对话框底部的下拉列表从" 仅用于此视图"更改为" 还更新会话默认值",然后再单击"确定".
six*_*ude 20
使用它将起作用:
git difftool --dir-diff --no-symlinks
Run Code Online (Sandbox Code Playgroud)
从git doc:
- [无糖]符号链接
git difftool的默认行为是在--dir-diff模式下运行时为工作树创建符号链接,并且比较的右侧产生与工作树中的文件相同的内容.
指定--no-symlinks指示git difftool改为创建副本.--no-symlinks是Windows上的默认设置.