1

I am trying to compare the difference between two repositories at given commits. The closest StackOverflow post that I've come across suggests adding one repo as a remote to compare with the working repo with below commands:

git remote add -f b path/to/repo_b.git
git remote update
git diff master remotes/b/master
git remote rm b

However, if I want to compare with the point at a specific past commit of the repo_b (and not just a branch), how can I do that?

Nasif Imtiaz Ohi
  • 1,563
  • 5
  • 24
  • 45

1 Answers1

1

Just use the commit hashes instead of the branch names in git diff. For example:

git remote add -f b path/to/repo_b.git
git remote update
git diff 547cd49 600cd49
git remote rm b

Commit hashes are unique over branches (and universe)

Julian
  • 33,915
  • 22
  • 119
  • 174
  • 1
    Commit hashes are unique over the universe! – matt Jun 23 '21 at 03:00
  • just to understand how is git inferring that `600cd49` comes from remote b. there could be multiple remotes right? – Nasif Imtiaz Ohi Jun 23 '21 at 03:02
  • 2
    Those are also unique. See comment @matt and I edited my answer to make that clear – Julian Jun 23 '21 at 03:04
  • 2
    @NasifImtiazOhi: this is, by the way, the reason that no part of any commit can ever change. The commit's hash ID is now allocated to *that* commit. You can make a new-and-improved commit that you use *instead of* the original, but you cannot change the original, as it may now appear in other Git repositories due to fetch or push. – torek Jun 23 '21 at 03:32
  • 1
    @NasifImtiazOhi It doesn't have "infer" anything. Either we have `600cd49` somewhere or we don't. It doesn't matter _how_ we obtained it. If we do have it, what's "in" it is what's "in" it, no matter where it came from, and we can compare that to any other commit. – matt Jun 23 '21 at 03:36