How can we get the difference between two git repositories?
The scenario: We have a repo_a and repo_b. The latter was created as a copy of repo_a. There have been pa
I use PyCharm which has great capabilities to compare between folders and files.
Just open the parent folder for both repos and wait until it indexes. Then you can use right click on a folder or file and Compare to...
and pick the corresponding folder / file on the other side.
It shows not only what files are different but also their content. Much easier than command line.
git diff master remotes/b
That's incorrect. remotes/b
is a remote, but not a branch.
To get it to work, I had to do:
git diff master remotes/b/master
You can add other repo first as a remote to your current repo:
git remote add other_name PATH_TO_OTHER_REPO
then fetch brach from that remote:
git fetch other_name branch_name:branch_name
this creates that branch as a new branch in your current repo, then you can diff that branch with any of your branches, for example, to compare current branch against new branch(branch_name):
git diff branch_name
See http://git.or.cz/gitwiki/GitTips, section "How to compare two local repositories" in "General".
In short you are using GIT_ALTERNATE_OBJECT_DIRECTORIES environment variable to have access to object database of the other repository, and using git rev-parse with --git-dir
/ GIT_DIR to convert symbolic name in other repository to SHA-1 identifier.
Modern version would look something like this (assuming that you are in 'repo_a'):
GIT_ALTERNATE_OBJECT_DIRECTORIES=../repo_b/.git/objects \ git diff $(git --git-dir=../repo_b/.git rev-parse --verify HEAD) HEAD
where ../repo_b/.git
is path to object database in repo_b (it would be repo_b.git if it were bare repository). Of course you can compare arbitrary versions, not only HEADs.
Note that if repo_a and repo_b are the same repository, it might make more sense to put both of them in the same repository, either using "git remote add -f ...
" to create nickname(s) for repository for repeated updates, or obe off "git fetch ...
"; as described in other responses.
In repo_a:
git remote add -f b path/to/repo_b.git
git remote update
git diff master remotes/b/master
git remote rm b
You can use the following command:
diff -x .git -r repo-A repo-B
or for the side by side you can use:
diff -x .git -W200 -y -r repo-A repo-B
In case of Colorizing every diff file, you can use:
diff -x .git -W200 -y -r repo-A repo-B | sed -e "s/\(^diff .*\)/\x1b[31m\1\x1b[0m/"