Home > Software design >  In a given repo, output the differences between two commits
In a given repo, output the differences between two commits

Time:05-13

When I want to see the output of the gif difference between given two commits SHAs (let's say 123ab45 and 678cd90), I use this git diff 123ab45 678cd90

But when the two commits that sit in a different repo, I am trying to figure out how to output them. Is there any specific command that will do the work with the repo name input?

Thanks

CodePudding user response:

The git command only operates on a single repository.

If the two repositories that you have are based on the same repository, eg. have been pulled from the same origin, but have different commits, then you can create a clone from one repository, add the second one as a remote and fetch all missing commits. You end up with a copy of the repository that has changes from both repositories. git diff will then work.

CodePudding user response:

You can git fetch any repository URL into any other repository. By default this will not leave permanent traces, i.e. it will download the objects but won't alter branches or other refs (as long as you don't get 'fetch' and 'pull' mixed up).

git fetch https://github.com/foo/bar

Note that this is done without adding a remote. (Although if you wanted to have branches from both repositories, then you could add a remote for the other repo.)

This works best if the two repositories have related histories, but that's not a requirement – fetching an unrelated repo will need to download all its data but won't otherwise harm the local repository. (If you fetch a URL without creating a remote, then all fetched data will get garbage-collected sometime later, as no branches reference it.)

  • Related