skiphoppy
skiphoppy

Reputation: 102793

How do I compare two git repositories?

I've got two different exports of our CVS repository into git. They diverge at some point, and I'm doing some investigation into why. The development line goes back several years and over tens of thousands of commits.

At the beginning of the development line, the SHA1 IDs for each commit are identical, telling me that git-cvsimport is very consistent about what it is doing when it reads the results of cvsps and imports.

But sometime between the first commit and yesterday, the SHA1 IDs begin to diverge. I'd like to find out where this is by comparing a list of commit IDs from each repository and looking to see what's missing. Are there any good tools or techniques for doing this?

Upvotes: 38

Views: 43454

Answers (6)

nobis99
nobis99

Reputation: 56

I had a similar need recently. I had a cloned remote project I needed to compare with a current copied code base. The git logs were not relevant, because the commits had nothing in common, and I was not sure they branched from the same code base.

To solve the problem, I used git in a brute force manner. I copied the files to be checked into the git repo, then checked the git status for a list changed files.

Additionally, git diff <filename> can also be used to inspect further. I was able to compare files within

Upvotes: 1

Jakub Narębski
Jakub Narębski

Reputation: 323504

You can put (fetch) both repositories into single repository, either new one, or one of existing, as in responses by ephemient, Charles Bailey and Brian Campbell. Or you can use trick from Tips and Tricks page on Git Wiki, or to be more exact "How to compare two local repositories" question there.

But it might be simpler to generate list of SHA-1 of commits in topological order using "git rev-list" (or "git-log" with appropriate options), and check the first revision they differ.

Upvotes: 1

ephemient
ephemient

Reputation: 204768

Since the two git repositories start out the same, you can pull both into the same working repository.

$ git remote add cvsimport-a git://.../cvsimport-a.git
$ git remote add cvsimport-b git://.../cvsimport-b.git
$ git remote update
$ git log cvsimport-a/master..cvsimport-b/master  # in B, not in A?
$ git log cvsimport-b/master..cvsimport-a/master  # in A, not in B?

Upvotes: 42

Brian Campbell
Brian Campbell

Reputation: 332846

In one of your repos, do the following:

$ git remote add other-repo git://.../other-repo.git
$ git remote update
$ git log other-repo/master...master
  # or maybe:
$ gitk master... other-repo/master

This gives you the symmetric difference between two repos; this shows you all of the commits that are in one repo, but not the other.

Upvotes: 15

Why not just cat each repo's git log to its own file and compare? The difference closest to the bottom of the file is where they started diverging...

Upvotes: 17

CB Bailey
CB Bailey

Reputation: 791929

The obvious way would be to clone one repository, fetch the tip of the main branch of the other repository into the clone and use git merge-base on the two tips to find the common ancestor.

Upvotes: 4

Related Questions