I have two repos that I've downloaded to my local machine (as .zip files that I unzipped) that are in separate folders. The contents are virtually the same, but there are thousands of files in them.
Is it possible to use Git to compare across them and find those minute changes? I suspect there are a handful of changes across 5-6 files but I need to find them.
I do have them both in Github if working with the uploaded versions is easier. If it matters (and I suspect it doesn't), my local environment is a Mac.
Note: Neither of these repos is a fork of the other. (One is a fork of a friend's repo; both repos share a recent common origin that we forked from)
There's a diff parameter --no-index
designed especially for this case
git diff [options] [--no-index] [--] <path> <path>
Also it can be done with --work-tree
parameter. It tells Git to use a different working tree (but the same repository).
cd path/to/project1
git --work-tree=path/to/project2 diff [options]
The output may be large and can be saved to a file by adding > filename.log
to the command line.
This shows you the differencies in files, not in commits. For commits, see How do I compare two git repositories?
From man git diff
(on Linux Ubuntu 20.04):
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.
So, apparently something like this would work:
git diff --no-index -- /some/path1 /some/path2
Store the output into a file with:
git diff --no-index -- /some/path1 /some/path2 > mydiff.txt
...or with color output via ANSI color codes:
git diff --no-index --color=always -- /some/path1 /some/path2 > mydiff.txt
You could also just manually force both sets of files into a new git repo to see how they differ:
# 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With