【问题标题】:Git difftool in Windows to see list of all changed files in addition to file diffs (a la Kaleidoscope)?Windows 中的 Git difftool 可以查看除文件差异之外的所有已更改文件的列表(如 Kaleidoscope)?
【发布时间】:2013-07-19 00:50:55
【问题描述】:

当我执行git difftool 时,Kaleidoscope 会在左侧边栏中显示所有已更改的文件:


(来源:kaleidoscopeapp.com

Windows 中是否有任何差异工具可以显示这样的文件列表?

(我不希望该工具在单独的窗口中同时打开所有文件。我正在寻找一个单独的窗口来显示已更改文件的列表,并且我应该能够单击特定文件以查看其差异,如 Kaleidoscope 屏幕截图所示)

【问题讨论】:

    标签: git diff kaleidoscope


    【解决方案1】:

    您可以使用 git difftool 列出所有文件(推荐 git1.8+):

    git difftool --dir-diff
    

    将修改后的文件复制到临时位置并对其执行目录差异。
    此模式在启动差异工具之前从不提示。

    然后你可以integrate it with a BeyondCompare for instance

    或使用 WinMerge:

    [diff]
        tool = winmerge
    [difftool "winmerge"]
        path = C:/Program Files (x86)/WinMerge/winmergeu.exe
        cmd = \"C:/Program Files (x86)/WinMerge/winmergeu.exe\" -r -u \"$LOCAL\" \"$REMOTE\"
    

    所有这些:

        $ git difftool [<commit> [<commit>]]
    

    唯一的问题是 git diff-tool 在 Windows 上由 in this blog post 描述,nitoyon

    在 Unix 和 MacOS 上,如果右侧文件与工作目录中的文件具有相同的 SHA1,git difftool --dir-diff 会创建一个指向工作目录的符号链接。当我们使用 difftool 修改右手文件时,它非常有用。

    在 Windows 上,git difftool --dir-diffdifftool 程序退出后将右侧文件复制回工作目录,而不是创建符号链接。我想在 Git 上为 Unix 和 MacOS 等 Windows 使用符号链接。

    注意:在 Windows 上,创建符号链接需要管理员权限

    以管理员身份运行 GitBash,输入以下命令。

    $ git difftool -d --symlinks [<commit> [<commit>]]
    

    如果需要,请在 .gitconfig 上创建一个别名。

    [alias]
        d = difftool -d --symlinks
    

    但这需要:

    • 创建git mklink 命令:
    C:\Program Files (x86)\Git\libexec\git-core\git-mklink:
    
    #!/bin/sh
    
    cmd.exe /c "mklink \"$2\" \"$1\"" > /dev/null
    
    • 修补 msysgit 1.8.3:
    cd /c/Program\ Files\ \(x86\)/Git/libexec/git-core/
    $ patch < ~/git-difftool.patch
    

    git-difftool.patch:

        --- git-difftool    Sun Jun  2 11:28:06 2013
        +++ git-difftool    Tue Jul  9 00:42:02 2013
        @@ -283,7 +283,7 @@
                    exit_cleanup($tmpdir, 1);
                }
                if ($symlinks) {
        -           symlink("$workdir/$file", "$rdir/$file") or
        +           !system("git", "mklink", "$workdir/$file", "$rdir/$file") or
                    exit_cleanup($tmpdir, 1);
                } else {
                    copy("$workdir/$file", "$rdir/$file") or
        @@ -448,7 +448,7 @@
            my $indices_loaded = 0;
        
            for my $file (@worktree) {
        -       next if $symlinks && -l "$b/$file";
        +       next if $symlinks;
                next if ! -f "$b/$file";
        
                if (!$indices_loaded) {
    

    在 Git 2.34(2021 年第四季度)之前,“git difftool --dir-diff(man) 符号链接处理不当。

    参见David Aguilar (davvid)commit 5bafb35(2021 年 9 月 22 日)。
    (由 Junio C Hamano -- gitster -- 合并到 commit 6a4f5da,2021 年 10 月 3 日)

    difftool: 修复 dir-diff 模式下的符号链接文件写入

    报告人:Alan Blotz
    帮助人:Đoàn Trần Công Danh
    签字人:David Aguilar支持>

    difftool dir-diff 模式通过将符号链接替换为它们的 readlink(2) 值来处理符号链接。
    这允许差异工具查看对符号链接的更改,就好像它们是具有旧路径值和新路径值的常规文本差异一样。
    这类似于符号链接更改时显示的“git diff(man)

    最初创建的临时差异目录包含符号链接,因为它们使用临时索引签出,该索引保留原始符号链接作为签入到存储库。

    在 C 中重写 difftool 时引入了一个错误,导致 difftool 将 readlink(2) 内容写入指向的文件而不是符号链接本身。
    写入是通过符号链接并写入其目标,而不是写入符号链接路径本身。

    通过在将 readlink(2) 内容写入其中之前取消链接符号链接路径,将符号链接替换为原始文本文件。

    18ec800("difftool:handle modified symlinks in dir-diff mode", 2017-03-15, Git v2.13.0-rc0 -- merge 列在batch #6) 中添加了对已修改的处理符号链接此错误已记录在测试套件中。
    测试包括指向的符号链接目标路径。
    这些路径被报告是因为 difftool 错误地写入它们,但它们不应该被报告或写入。

    通过从预期输出中删除目标文件来更正修改后的符号链接测试用例。

    而且,仍然是 Git 2.34:

    请参阅commit 28c10eccommit 8e2af8fcommit 2255c80commit 4ac9f15(2021 年 9 月 30 日)David Aguilar (davvid)
    请参阅 commit 77bd616(2021 年 9 月 23 日)和 commit 93a8ed2(2021 年 9 月 20 日)Junio C Hamano (gitster)
    (由 Junio C Hamano -- gitster -- 合并于 commit 0cc4ec1,2021 年 10 月 11 日)

    difftool: 重构 dir-diff 以使用辅助函数写入文件

    签字人:大卫·阿吉拉尔

    添加一个辅助函数来处理取消链接并写入 dir-diff 子模块和符号链接替代文件。

    使用帮助器来实现 hashmap 循环的核心。
    这消除了重复代码并保护子模块 hashmap 循环免受 5bafb35 ("difftool: fix symlink-file writing in dir-diff mode", 2021-09-22, Git v2.34.0 -- merge 列在 batch #10) 中。

    子模块循环不应该严格要求这是向它们引入的unlink() 调用,但除了额外的unlink() 的成本之外,它也不一定会伤害它们。

    /* Write the file contents for the left and right sides of the difftool
     * dir-diff representation for submodules and symlinks. Symlinks and submodules
     * are written as regular text files so that external diff tools can diff them
     * as text files, resulting in behavior that is analogous to to what "git diff"
     * displays for symlink and submodule diffs.
     */
    static void write_standin_files() {...}
    

    【讨论】:

    • 在 Windows 上创建不需要始终以管理员权限运行的符号链接还有两种可能性: 1. 禁用 UAC。 2. 使用非管理员账户的本地SSH服务器并调用'ssh user@localhost mklink foo bar'。
    猜你喜欢
    • 2012-04-07
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-11
    • 2020-01-18
    • 1970-01-01
    相关资源
    最近更新 更多