4

I'm interested in seeing which files have been modified in a (GitHub) pull request, compared to the current master branch.

It would be optimal if this would work without checking out or changing files locally - just display which files (filenames including paths) have been touched in a PR.

How can this be accomplished?

derFunk
  • 1,587
  • 2
  • 20
  • 31

3 Answers3

9

What I do in general: on the github's page for the pull request, you will find at the bottom a link that says " ProTip! Add .patch or .diff to the end of URLs for Git’s plaintext views.". The url for the .patch looks something like:

https://github.com/git/git/pull/309.patch

(so from the command line you can simply substitute the pull request number, and don't in fact need to look at the github page everytime).

Once you have this URL, use something like:

curl -s -L https://github.com/git/git/pull/309.patch | git apply --stat -

which will show output similar to:

git-p4.py |   36 ++++++++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 6 deletions(-)
manuBriot
  • 2,755
  • 13
  • 21
  • Good one! This pushed me in the right direction.This satisfies my requirement to not touch local files. The GitHub WebHook API also reports the API Url to the pull request (which looks like this `https://api.github.com/repos/${opts.owner}/${opts.repo}/pulls/${opts.pr}.patch` , which is also reported from the GitHub WebHook API which I'm using. For private repos one can add the `?access_token=TOKEN` GET-parameter. Also this header should be added: `-H "Accept: application/vnd.github.3.patch" ` The output then can further be parsed on the shell. Marking this as the solution, thanks a lot! – derFunk Dec 14 '16 at 12:40
4

This info is all in your local git history and requires two steps (which can be combined)

What is the last common commit

The commit used to create the PR branch is necessary to know what to compare to, to find this use git merge-base. This is most relevant if the branch has existed for some time, other changes have been merged to master, and the PR branch is out of date with the current master.

$ git merge-base origin/pr-branch-name origin/master
somehash

This is the first commit which is common to both branches, and the commit to compare to.

What are the files that differ between two commits

To get a list of files that differ, use git-diff with the option --name-only

$ git diff --name-only origin/pr-branch-name somehash
src/x
src/y
...

As one command

As a single command that would be:

$ git fetch # if desired
$ PR=pr-branch-name
$ git diff --name-only origin/$PR `git merge-base origin/$PR origin/master`
src/x
src/y
...
AD7six
  • 63,116
  • 12
  • 91
  • 123
3

There's now a reasonable way to do this purely from the GitHub UI. On the "Files changed" tab of a pull request, there's an arrow next to each filename that will collapse (or expand) the diff for a given file. If you hold the Alt key while clicking this arrow, it will collapse the diffs for all files, leaving you with just the filenames and diff stats.

Jordan C
  • 117
  • 3