hg 或 git 中的两个完整目录/项目之间存在差异?
我继承了一个最初存储在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
要简单地从两个任意文件或目录以 git 的 diff 格式创建一个 diff 补丁,没有任何花哨的存储库内容或版本控制:
Jakub Narębski 对 knittl 答案的评论暗示了答案...为了简单起见,这就是完整的命令。
>
部分创建一个文件并将输出重定向到该文件。如果您不需要文件而只想将输出打印在控制台中以便可以复制它,只需删除>; some_filename
部分。为了方便复制和粘贴,如果您已经
cd
到包含名为a
的原始目录/文件和修改后的目录b
的目录,它将是: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:
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
cd
ed to a directory containing the original directory/file nameda
and the modified directoryb
, it'll be:来自
git diff
手册页:如果您想比较两个不同存储库中的两个版本(例如两个标记版本或两个分支),您可以使用 GitTips 页面,位于“如何比较两个本地存储库”下。
假设您位于一个存储库中,第二个存储库位于
/path/to/repo
中,因此其 GIT_DIR 为/path/to/repo/.git
如果是非裸存储库,您可以执行以下操作:其中 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: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: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 togit-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
(andgit fetch
). Then you would have everything locally, and would be able to do comparision inside single repository.是的。我们可以将当前目录与另一个目录进行 git diff 并...
...标记添加、删除和修改的文件:
...仅显示添加的文件文件:
...仅显示已删除的文件:
...仅显示修改的文件:
另请参阅:https://git-scm.com/docs/git-diff
Yes. We can
git diff
the current directory against another directory and......mark the added, deleted, and modified files:
...show only added files:
... show only deleted files:
...show only modified files:
See also: https://git-scm.com/docs/git-diff
它不是特定于 git 的,但作为 Windows 的通用 diff 实用程序,我真的很喜欢 WinMerge。
It's not git-specific, but as a general diff utility for Windows, I really like WinMerge.
我不太明白你想要什么,但是
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.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还有以下另一种方法可以区分两个整个目录/项目。
语法:git-diff [] [--] [... ]
这个表单是查看你相对于索引(下一次提交的暂存区)所做的更改。换句话说,差异就是您可以告诉 Git 进一步添加到索引中但您仍然没有添加的内容。
这是.
网址: https://git-scm.com/docs/git-diff
git diff --no-index 目录 1 项目/路径 目录 2 项目/路径 >>文件名
使用 Linux 命令 diff --brief --recursive dir1path/ dir2Path/
如果您使用的是 Windows,则有一个应用程序 WinMerge。
There Are Following Another Ways For Diffing between two entire directories/projects.
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
Using Linux Command diff --brief --recursive dir1path/ dir2Path/
If you are using windows there is an application WinMerge.
创建从 dir1 到 dir2 的补丁(
--binary
仅适用于二进制文件):将补丁应用于工作目录的内容,该目录与 dir1 具有相同的内容:
git apply
有默认的-p1
,它会删除 diff 命令中的前导目录。Creating the patch from dir1 to dir2 (
--binary
only needed for binaries):Applying the patch to contents of working directory, which has the same contents as dir1:
git apply
has default-p1
which strips the leading directories in diff commands.在 Ubuntu 中,可以使用 diff 命令:
输出到文件:
In Ubuntu, one can use the
diff
command:to output to a file: