github-apigit-diff

How can I get a *complete* list of changed files between two commits in github


(I know similar questions have been asked e.g. GitHub API - how to compare 2 commits but I don't think this is a duplicate)

As part of our build process we need to compare two commits in github and iterate through every file changed between them. There is a lovely API for comparing commits but it silently maxes out at 300 file changes, and while the API supports pagination you can only page through the list of commits, not the associated list of files. All my googling suggests that neither the gh CLI interface or the GraphQL API support diffing commit Ids either.

As best I can tell my options are

  1. clone the whole repo on every build and run git diff $lastReleaseHash...$newReleaseHash --name-status at the command line, which just seems inefficient
  2. Call github's compare API but ignore the list of files as it will max out at 300, instead page through all commits, then for each commit request the list of changed files, then manually stitch them together into an overall diff (i.e. tracking renames between commits, ignoring files that were created and then deleted within the range of commits, super tedious and error-prone)

Surely there are better options?!


Solution

  • You can use

    git clone --bare
    

    To clone the repository with just the VC information (no files). Then do a git diff.