hg 或 git 中的两个完整目录/项目之间存在差异?

发布于 2024-08-12 10:41:26 字数 158 浏览 7 评论 0原文

我继承了一个最初存储在 CVS 中的项目以及所有修订。我做了相当多的编辑,并且我试图比较我在原始目录中所做的所有更改,关于添加的新文件与旧文件。

hg/git 是否有某种实用程序可以让我进行树差异或类似性质的操作?也就是说,新添加的文件、删除的文件之间有一个标记,我的要求是否太高了?

I inherited a project originally stored in CVS with all the revisions. I made quite a few edits, and I'm trying to compare all the changes I made in the original directory, in regards to new files added versus the old ones.

Is there some sort of utility for hg/git where I can do a tree diff, or something of that nature? So that say, there's a mark between newly added files, deleted files, am I asking for too much?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

第七度阳光i 2024-08-19 10:41:26

简单地从两个任意文件或目录以 git 的 diff 格式创建一个 diff 补丁没有任何花哨的存储库内容或版本控制

git diff --no-index some/path other/path > some_filename

Jakub Narębski 对 knittl 答案的评论暗示了答案...为了简单起见,这就是完整的命令。

> 部分创建一个文件并将输出重定向到该文件。如果您不需要文件而只想将输出打印在控制台中以便可以复制它,只需删除 >; some_filename 部分。


为了方便复制和粘贴,如果您已经 cd 到包含名为 a 的原始目录/文件和修改后的目录 b 的目录,它将是:

git diff --no-index a b > patch

To simply create a diff patch in git's diff format from two arbitrary files or directories, without any fancy repository stuff or version control:

git diff --no-index some/path other/path > some_filename

Jakub Narębski's comment on knittl's answer hinted at the answer... For simplicity's sake, that's the full command.

The > part creates a file and redirects the output to it. If you don't want a file and just want the output printed in your console so you can copy it, just remove the > some_filename part.


For convenient copying and pasting, if you've already cded to a directory containing the original directory/file named a and the modified directory b, it'll be:

git diff --no-index a b > patch
∞梦里开花 2024-08-19 10:41:26

来自 git diff 手册页

git diff [--选项] [--] [<路径>...]

<块引用>

[...]
如果恰好给出了两个路径,并且至少有一个未跟踪,则比较这两个文件/目录。此行为可以通过 --no-index 强制。


如果您想比较两个不同存储库中的两个版本(例如两个标记版本或两个分支),您可以使用 GitTips 页面,位于“如何比较两个本地存储库”下。

假设您位于一个存储库中,第二个存储库位于 /path/to/repo 中,因此其 GIT_DIR 为 /path/to/repo/.git 如果是非裸存储库,您可以执行以下操作:

$ GIT_ALTERNATE_OBJECT_DIRECTORIES=/path/to/repo/.git/objects \
   git diff $(git --git-dir=/path/to/repo/.git rev-parse --verify A) B

其中 A 和 B 是您要比较的修订版本。当然你也可以在上面的表达式中指定路径限制器。

说明: GIT_ALTERNATE_OBJECT_REPOSITORIES 变量可用于使 git 命令连接两个存储库的对象数据库。 git --git-dir=... rev-parse ... 用于将存储库中的名称(扩展 SHA-1 表达式)作为参数传递给 git-dir 选项插入唯一的 SHA-1 标识符。 $( ... ) 构造将调用给定命令的结果放入命令行中。 git diff 用于比较两个修订(其中一个来自备用对象存储库)。

另一种解决方案是简单地导入其他存储库到给定存储库,使用git Remote add(和git fetch)。然后,您将在本地拥有所有内容,并且能够在单个存储库中进行比较。

From git diff manpage:

git diff [--options] [--] [<path>...]

[...]
If exactly two paths are given, and at least one is untracked, compare the two files / directories. This behavior can be forced by --no-index.


If you want to compare two versions (e.g. two tagged releases, or two branches) in two different repositories, you can use trick described in GitTips page on Git Wiki, under "How to compare two local repositories".

Assuming that you are inside one repository, and second repository is in /path/to/repo, so its GIT_DIR is /path/to/repo/.git if it is non-bare repository, you can something like the following:

$ GIT_ALTERNATE_OBJECT_DIRECTORIES=/path/to/repo/.git/objects \
   git diff $(git --git-dir=/path/to/repo/.git rev-parse --verify A) B

where A and B are revisions you want to compare. Of course you can also specify path limiter in above expression.

Explanation: GIT_ALTERNATE_OBJECT_REPOSITORIES variable can be used to make git commands concatenate object database of the two repositories. git --git-dir=... rev-parse ... is used to turn name (extended SHA-1 expression) in repository given as parameter to git-dir option into unique SHA-1 identifier. The $( ... ) construct puts result of calling given command in command line. git diff is used to compare two revisions (where one is from alternate object repository).

Alternate solution would be to simply import other repository into given repository, using git remote add (and git fetch). Then you would have everything locally, and would be able to do comparision inside single repository.

×纯※雪 2024-08-19 10:41:26

是否有某种适用于 hg/git 的实用程序,我可以在其中进行树差异...[s]o 说,新添加的文件、删除的文件之间有一个标记... [已添加强调]

是的。我们可以将当前目录与另一个目录进行 git diff 并...

...标记添加、删除和修改的文件:

git diff --name-status --no-index ./ path/to/other/dir

...仅显示添加的文件文件:

git diff --diff-filter=A --name-status --no-index ./ path/to/other/dir

...仅显示已删除的文件:

git diff --diff-filter=D --name-status --no-index ./ path/to/other/dir

...仅显示修改的文件:

git diff --diff-filter=M --name-status --no-index ./ path/to/other/dir

另请参阅:https://git-scm.com/docs/git-diff

Is there some sort of utility for hg/git where I can do a tree diff... [s]o that say, there's a mark between newly added files, deleted files... [emphasis added]

Yes. We can git diff the current directory against another directory and...

...mark the added, deleted, and modified files:

git diff --name-status --no-index ./ path/to/other/dir

...show only added files:

git diff --diff-filter=A --name-status --no-index ./ path/to/other/dir

... show only deleted files:

git diff --diff-filter=D --name-status --no-index ./ path/to/other/dir

...show only modified files:

git diff --diff-filter=M --name-status --no-index ./ path/to/other/dir

See also: https://git-scm.com/docs/git-diff

我是男神闪亮亮 2024-08-19 10:41:26

它不是特定于 git 的,但作为 Windows 的通用 diff 实用程序,我真的很喜欢 WinMerge

It's not git-specific, but as a general diff utility for Windows, I really like WinMerge.

日暮斜阳 2024-08-19 10:41:26

我不太明白你想要什么,但是 diff -ur 对你来说还不够吗?它甚至可以在没有任何版本控制的目录上工作。

I don't really understand what you want, but isn't diff -ur enough for you? It will work even on directories without any kind of version control.

扛起拖把扫天下 2024-08-19 10:41:26

git diff 正是这样做的。但它只适用于 git 项目。

hg diff, svn diff 几乎每个版本控制系统都可以比较目录树

git diff does exactly that. but it only works for git projects.

hg diff, svn diff pretty every version control system can diff directory trees

一抹微笑 2024-08-19 10:41:26

还有以下另一种方法可以区分两个整个目录/项目。

  1. 在 Git 中有语法:

语法:git-diff [] [--] [... ]
这个表单是查看你相对于索引(下一次提交的暂存区)所做的更改。换句话说,差异就是您可以告诉 Git 进一步添加到索引中但您仍然没有添加的内容。

这是.
网址: https://git-scm.com/docs/git-diff

git diff --no-index 目录 1 项目/路径 目录 2 项目/路径 >>文件名

  1. 使用 Linux 命令 diff --brief --recursive dir1path/ dir2Path/

  2. 如果您使用的是 Windows,则有一个应用程序 WinMerge

There Are Following Another Ways For Diffing between two entire directories/projects.

  1. In Git There is Syntax:

Syntax: git-diff [] [--] […​]
This form is to view the changes you made relative to the index (staging area for the next commit). In other words, the differences are what you could tell Git to further add to the index but you still haven’t.

Here is the.
URL: https://git-scm.com/docs/git-diff

git diff --no-index directory 1 project /path directory 2 project/path >> File name

  1. Using Linux Command diff --brief --recursive dir1path/ dir2Path/

  2. If you are using windows there is an application WinMerge.

病女 2024-08-19 10:41:26

创建从 dir1 到 dir2 的补丁(--binary 仅适用于二进制文件):

git diff --no-prefix --no-index --binary dir1 dir2 > dir.diff

将补丁应用于工作目录的内容,该目录与 dir1 具有相同的内容:

cd dir1_copy
git apply ../dir.diff

git apply有默认的 -p1 ,它会删除 diff 命令中的前导目录。

Creating the patch from dir1 to dir2 (--binary only needed for binaries):

git diff --no-prefix --no-index --binary dir1 dir2 > dir.diff

Applying the patch to contents of working directory, which has the same contents as dir1:

cd dir1_copy
git apply ../dir.diff

git apply has default -p1 which strips the leading directories in diff commands.

ゝ杯具 2024-08-19 10:41:26

在 Ubuntu 中,可以使用 diff 命令:

diff dir1 dir2

输出到文件:

diff dir1 dir2 > diffs.txt

In Ubuntu, one can use the diff command:

diff dir1 dir2

to output to a file:

diff dir1 dir2 > diffs.txt
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文