是否可以比较 Git 中的两个目录[重复]

问题描述 投票:0回答:2

我已经在 Git 中安装了 Meld 作为 diff 工具。是否可以使用 Git 或任何其他方式比较两个文件夹?我尝试了以下命令,但没有任何反应。

git diff /c/sample/folder1/ /c/sample/folder2/
git diff meld
2个回答
16
投票

如果您想比较磁盘上的两个目录,则不需要

git
:

# use any suitable diff viewer : meld, kdiff3 ...
meld /c/sample/folder1/ /c/sample/folder2/

如果你想在 git 中获得两次提交之间差异的目录视图:

git difftool -d <commit1> <commit2>

# you can also restrict this directory view to a subdir of your repo :
git difftool -d <commit1> <commit2> -- lib/

[更新]回答@DamianBirchler 评论:

比较提交中的两个目录:

git difftool -d <commit>:path/to/dir1 <commit>:path/to/dir2

这实际上适用于任何两个提交(实际上指向 git 中的两棵树的任何内容):

git difftool -d <commit1>:config  <commit2>:new/path/to/config

4
投票

使用 git diff master..yourbranch path/to/folder 比较 git 存储库中文件夹的不同

版本
实际上是完全正常的(请参阅this问题)。

如果不是关于版本,而只是比较两个文件夹,meld 可以做到:

Meld 可让您并排比较两个或三个文件夹。你可以开始了 通过选择“文件”▸“新建...”菜单项来比较新文件夹,以及 单击“目录比较”选项卡。

(来自这里)。

© www.soinside.com 2019 - 2024. All rights reserved.