我有两个代码库,它们分别在不同的文件夹中,是我从本地机器上下载的(以.zip文件形式并解压)。它们的内容几乎相同,但其中有成千上万个文件。
是否可能使用Git跨库比较并查找那些微小的更改?我怀疑在5-6个文件中有少量的更改,但我需要找到它们。
如果使用上传版本更容易处理,我确实已将它们都上传至Github。如果有影响的话(我怀疑没有),我的本地环境是Mac。
注意:这两个代码库都不是彼此的分支(其中一个是朋友的代码库的分支;两个代码库共享最近的公共起源,我们都是从那里fork出来的)
我有两个代码库,它们分别在不同的文件夹中,是我从本地机器上下载的(以.zip文件形式并解压)。它们的内容几乎相同,但其中有成千上万个文件。
是否可能使用Git跨库比较并查找那些微小的更改?我怀疑在5-6个文件中有少量的更改,但我需要找到它们。
如果使用上传版本更容易处理,我确实已将它们都上传至Github。如果有影响的话(我怀疑没有),我的本地环境是Mac。
注意:这两个代码库都不是彼此的分支(其中一个是朋友的代码库的分支;两个代码库共享最近的公共起源,我们都是从那里fork出来的)
针对这种情况,有一个名为--no-index
的diff参数专门设计而来。
git diff [options] [--no-index] [--] <path> <path>
--work-tree
参数来完成。它告诉Git使用不同的工作树(但是相同的存储库)。cd path/to/project1
git --work-tree=path/to/project2 diff [options]
> filename.log
将其保存到文件中。(参考链接)
这将显示文件之间的差异,而不是提交。有关提交,请参见如何比较两个git存储库?
git diff --work-tree=../proj2
时,它会显示error:invalid option --work-tree=../proj2
。(当我将diff
移动到标志之后,就像你的示例一样,它什么也没做) - zahabba--no-index
参数。 - Nick Volynkingit diff --no-index . ../proj2
时它能够正常工作。你知道如何将输出保存为文本文件吗?(比我想象的要长)谢谢! - zahabba来自Linux Ubuntu 20.04上 man git diff
的说明:
git diff [<options>] --no-index [--] <path> <path>
This form is to compare the given two paths on the
filesystem. You can omit the --no-index option when
running the command in a working tree controlled by Git
and at least one of the paths points outside the
working tree, or when running the command outside a
working tree controlled by Git. This form implies
--exit-code.
所以,显然像这样的东西可以起作用:
git diff --no-index -- /some/path1 /some/path2
使用以下方式将输出存储到文件中:
git diff --no-index -- /some/path1 /some/path2 > mydiff.txt
...或通过ANSI颜色代码输出带有颜色的内容:
git diff --no-index --color=always -- /some/path1 /some/path2 > mydiff.txt
您也可以将两组文件手动强制合并到一个新的git仓库中,以查看它们的差异:
# make a new git repo
mkdir newrepo
cd newrepo
git init
# copy the first set of files into it (manually delete the .git
# folder in this set of files **before copying them**, if it has one,
# as you do NOT want to overwrite the destination .git folder)
cp -r /some/path1 .
# add them to the repo
git add -A
git commit
# manually delete everything in the repo except the .git folder
# copy 2nd set of files into repo (manually delete the .git
# folder in this set of files **before copying them**, if it has one,
# as you do NOT want to overwrite the destination .git folder)
cp -r /some/path2 .
# add them to the repo
git add -A
git commit
# compare the two sets of files by comparing your previous
# commit (with files from "/some/path1") to your current
# commit (with files from "/some/path2").
git diff HEAD~..HEAD
# OR (same thing):
git diff HEAD~
man git diff