Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 776
Alfred Xing Avatar asked Aug 01 '14 01:08

Alfred Xing


People also ask

How do you see what files were changed in git?

To find out which files changed in a given commit, use the git log --raw command. It's the fastest and simplest way to get insight into which files a commit affects.

How do you suggest changes in a pull request?

In the list of pull requests, click the pull request you'd like to apply a suggested change to. Navigate to the first suggested change you'd like to apply. To apply the change in its own commit, click Commit suggestion. To add the suggestion to a batch of changes, click Add suggestion to batch.


2 Answers

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.

like image 75
zanerock Avatar answered Nov 10 '22 01:11

zanerock


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
like image 26
zoispag Avatar answered Nov 09 '22 23:11

zoispag