List all files changed in a pull request in Git/GitHub

Using GitHub cli (gh) you can run:

gh pr view 2615 --json files --jq '.files.[].path'

I have made a gh alias because I use it regularly:

gh alias set pr_files "pr view $1 --json files --jq '.files.[].path'"

and then I call it with gh pr_files 2615 or gh pr_files 2615 | cat

gh pr_files 2615 | cat

In general, you can list the files changed between any two commits with git diff --name-only :

How to list only the file names that changed between two commits?

The problem here seems to be determining the 'merge base'. If all branches originate with master, then you could do:

git --no-pager diff --name-only FETCH_HEAD $(git merge-base FETCH_HEAD master)

This will show you the changes between the point at which the FETCH_HEAD was branched from master to the current FETCH_HEAD. I tested this locally, and the PR branches are cut from master I believe it should work.


For GitHub specifically, this can be accomplished using the REST API:

GET /repos/:owner/:repo/pulls/:pull_number/files

You can use one of the GitHub libraries for this purpose.


Chrome console...

Note: This will break if Github changes the tags/classes/IDs in the page.

const fileElems = document.querySelectorAll('#files div.js-diff-progressive-container div.file div.file-header div.file-info a.Link--primary');
const filePaths = [];
        
for (let a of fileElems) {
    filePaths.push(a.title);
}
    
const filePathsStr = filePaths.join('\n');
console.log(filePathsStr);
copy(filePathsStr);
console.log('Copied to the clipboard as well 😁');