我已经下载了两个repos到我的本地机器上(作为我解压的.zip文件),它们分别位于不同的文件夹中。内容实际上是相同的,但其中有数千个文件。
有没有可能使用Git在它们之间进行比较,并找到那些微小的变化?我怀疑在5-6个文件中有一些变化,但我需要找到它们。
如果使用上传的版本更容易,我确实在Github中有这两个版本。如果这很重要(我怀疑它并不重要),那么我的本地环境就是Mac。
注意:这两个repos都不是另一个的分支。(一个是一个朋友的repo的分支;两个repo共享一个最近的共同来源,我们是从这个分支派生的)
发布于 2015-06-11 13:08:26
有一个专门为这种情况设计的diff参数--no-index
git diff [options] [--no-index] [--] <path> <path>也可以使用--work-tree参数来完成。它告诉Git使用不同的工作树(但相同的存储库)。
cd path/to/project1
git --work-tree=path/to/project2 diff [options]输出可能很大,可以通过在命令行中添加> filename.log将其can be saved到文件中。
这将显示文件的差异,而不是提交的差异。有关提交的信息,请参阅How do I compare two git repositories?
发布于 2020-10-22 00:49:36
从man git diff (在Linux Ubuntu20.04上):
index git diff -- no-
--此格式用于比较文件系统上给定的两个路径。在由Git控制的工作树中运行该命令时,或者在由Git控制的工作树外运行该命令时,可以省略--no-index选项。这种形式意味着--exit-code。
所以,很明显,像这样的东西是可行的:
git diff --no-index -- /some/path1 /some/path2使用以下命令将输出存储到文件中:
git diff --no-index -- /some/path1 /some/path2 > mydiff.txt具有通过ANSI色码输出的颜色的...or:
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 diffhttps://stackoverflow.com/questions/30771920
复制相似问题