36

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?

Brian
  • 4,931
  • 3
  • 32
  • 55
skiphoppy
  • 97,646
  • 72
  • 174
  • 218

6 Answers6

41

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?
ephemient
  • 198,619
  • 38
  • 280
  • 391
  • You're probably going to need cvsimport-a/master and cvsimport-b/master in those commands. Also, you can do "git remote update" instead of piping to xargs git fetch. – Brian Campbell Mar 26 '09 at 20:53
  • I was originally going to write `git remote fetch cvsimport-a; git remote fetch cvsimport-b` (not updating any other remotes), but then I changed my mind... done. Git complains a little if you leave off /master but it works. I'll change it for clarity. – ephemient Mar 26 '09 at 21:08
17

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...

Restore the Data Dumps
  • 38,967
  • 12
  • 96
  • 122
  • This is actually what I wound up doing yesterday, although today I'm getting a little more advanced with some suggestions from the other answers. – skiphoppy Mar 27 '09 at 20:06
  • 4
    seing where two repositories started diverging is a long way from telling me the differences that were created since that divergence. – masukomi Jul 04 '12 at 23:49
  • Sorry but that's not what the question was. The question is how do you compare two repos. Answer is below. – awm Jul 08 '15 at 09:37
15

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.

Brian Campbell
  • 322,767
  • 57
  • 360
  • 340
4

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.

CB Bailey
  • 755,051
  • 104
  • 632
  • 656
  • 6
    'Fetch the tip of main branch of the other repo' - How to do that? Asking for a friend. :/ – Darpan Aug 16 '18 at 07:57
  • 2
    Downvoting for starting an answer with "The obvious way", and then assuming said way is obvious enough to not actually write out the answer! – Lou Oct 03 '22 at 16:34
1

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

nobis99
  • 56
  • 3
1

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.

tvsaru
  • 23
  • 5
Jakub Narębski
  • 309,089
  • 65
  • 217
  • 230
  • Tips and Tricks link gives a "Not Found", has it moved or is it gone? – Chris Apr 16 '12 at 16:20
  • 1
    Git Wiki first moved from http://git.or.cz to http://git.wiki.kernel.org but second after break-in into kernel.org is not yet back (and it is not known if it would be beack there, or maybe somewhere at http://git-scm.com). http://git.wiki.kernel.org is in read-only mode so all links changed. **Tips and Tricks** (aka **GitTips**) is available here: https://git.wiki.kernel.org/articles/g/i/t/GitTips_81aa.html – Jakub Narębski Apr 16 '12 at 18:23