在 hg 或 git 中的两个完整目录/项目之间存在差异?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1791854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Diffing between two entire directories/projects in hg or git?
提问by meder omuraliev
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.
我继承了一个最初存储在 CVS 中的项目,其中包含所有修订。我做了很多编辑,我试图比较我在原始目录中所做的所有更改,关于添加的新文件与旧文件。
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?
是否有某种适用于 hg/git 的实用程序,我可以在其中进行树差异或类似的事情?这么说来,新加的文件和删除的文件之间有一个标记,是不是我要求的太多了?
采纳答案by knittl
git diff
does exactly that. but it only works for git projects.
git diff
正是这样做的。但它只适用于 git 项目。
hg diff
, svn diff
pretty every version control system can diff directory trees
hg diff
,svn diff
几乎每个版本控制系统都可以区分目录树
回答by user56reinstatemonica8
To simply create a diff patchin git's diff format from two arbitrary files or directories, without any fancy repository stuff or version control:
为了简单地创建一个diff补丁从任意两个文件或目录的混帐的DIFF格式,没有任何花哨的东西,仓库或版本控制:
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.
Jakub Nar?bski 对 knittl 的回答的评论暗示了答案......为简单起见,这就是完整的命令。
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.
该>>
部件创建一个文件并将输出重定向到该文件。如果您不想要文件而只想在控制台中打印输出以便您可以复制它,只需删除该>> some_filename
部分即可。
For convenient copying and pasting, if you've already cd
ed to a directory containing the original directory/file named a
and the modified directory b
, it'll be:
为了方便复制和粘贴,如果您已经cd
编辑到包含原始目录/文件a
和修改后的目录的目录b
,它将是:
git diff --no-index a b >> patch
回答by Jakub Nar?bski
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
.
git diff [--options] [--] [<path>...]
[...]
如果恰好给出了两个路径,并且至少有一个未跟踪,请比较两个文件/目录。可以强制执行此行为--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 GitTipspage on Git Wiki, under "How to compare two local repositories".
如果您想比较两个不同存储库中的两个版本(例如,两个标记版本或两个分支),您可以使用Git Wiki 上的GitTips页面中描述的技巧,在“如何比较两个本地存储库”下。
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:
假设您在一个存储库中,第二个存储库在 中/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
where A and B are revisions you want to compare. Of course you can also specify path limiter in above expression.
其中 A 和 B 是您要比较的修订版。当然你也可以在上面的表达式中指定路径限制器。
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).
说明:GIT_ALTERNATE_OBJECT_REPOSITORIES
变量可用于使 git 命令连接两个存储库的对象数据库。 git --git-dir=... rev-parse ...
用于将存储库中作为参数提供给git-dir
选项的名称(扩展 SHA-1 表达式)转换为唯一的 SHA-1 标识符。该$( ... )
构造将调用给定命令的结果放在命令行中。 git diff
用于比较两个修订版(其中一个来自备用对象存储库)。
Alternate solution would be to simply importother 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.
替代解决方案是简单地使用(和)将其他存储库导入给定存储库。然后您将在本地拥有所有内容,并且能够在单个存储库中进行比较。git remote add
git fetch
回答by Shaun Luttin
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]
是否有某种适用于 hg/git 的实用程序,我可以在其中进行树差异... [s]o 也就是说,在新添加的文件、已删除的文件之间有一个标记... [强调添加]
Yes. We can git diff
the current directory against another directory and...
是的。我们可以git diff
将当前目录针对另一个目录,然后...
...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
回答by Andy West
回答by Thiago Arrais
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.
我真的不明白你想要什么,但diff -ur
对你来说还不够吗?它甚至可以在没有任何版本控制的目录上工作。
回答by Samir Lakhani
There Are Following Another Ways For Diffing between two entire directories/projects.
有以下另一种方法可以在两个整个目录/项目之间进行区分。
- In Git There is Syntax:
- 在 Git 中有语法:
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.
语法:git-diff [] [--] […?] 这个表格是查看你相对于索引所做的更改(下一次提交的暂存区)。换句话说,不同之处在于您可以告诉 Git 进一步添加到索引中,但您仍然没有。
Here is the. URL: https://git-scm.com/docs/git-diff
这里是。网址:https: //git-scm.com/docs/git-diff
git diff --no-index directory 1 project /path directory 2 project/path >> File name
git diff --no-index directory 1 project /path directory 2 project/path >> 文件名
Using Linux Commanddiff --brief --recursive dir1path/ dir2Path/
If you are using windows there is an application WinMerge.
使用Linux 命令diff --brief --recursive dir1path/ dir2Path/
如果您使用的是 Windows,则有一个应用程序WinMerge。