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

Alfred Xing picture Alfred Xing · Aug 1, 2014 · Viewed 32k times · Source

Is there a way (from the command line) to list the names of all files changed in a PR in Git/GitHub? This would be used to find what tests need to be run in a Travis CI build for that PR.

The CI build runs these commands before it calls our script:

git clone --depth=50 git://github.com/jekyll/jekyll.git jekyll/jekyll
cd jekyll/jekyll
git fetch origin +refs/pull/2615/merge
git checkout -qf FETCH_HEAD

Answer

zanerock picture zanerock · Aug 1, 2014

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.