From git diff
manpage:
git diff [--options] [--] [<path>...]
[...]
If exactly two paths are given, and at least one is untracked, compare the two files / directories. This behavior can be forced by --no-index
.
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:
$ GIT_ALTERNATE_OBJECT_DIRECTORIES=/path/to/repo/.git/objects \
git diff $(git --git-dir=/path/to/repo/.git rev-parse --verify A) B
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 to git-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
(and git fetch
). Then you would have everything locally, and would be able to do comparision inside single repository.
git diff master..yourbranch path/to/folder
– Creamy