Reviewing a Subset of Commits in a GitHub Pull Request

Authored by

For many years now, GitHub has provided a compare view to see the differences between any two commits, taking the form of:

http://github.com/<USER>/<REPO>/compare/[<START>...]<END>

This has been useful in the context of long-running pull requests to see just a subset of the changes. But there has been a big problem with this view: you cannot comment on such a compare view like you can on a pull request diff.

As of March 2016, GitHub added the ability to pick up where you left off with a pull request timeline entry for “New changes since you last viewed” with a link to “View changes”:

While code review is essential for high quality code, it can be a long and tiring process, especially for projects with many incoming pull requests. It’s often most helpful to view just the new changes that have occured after you have reviewed a pull request, so we’ve added a timeline indicator to help you get to those changes, faster.

This has been really helpful. However, this link to view changes is very shy. Too often I’ll go to a pull request, make a comment, and then want to come back later to continue reviewing the new changes; but when I come back, that timeline entry has disappeared. There is no apparent UI for re-accessing this “pull request subset compare view”. But it turns out there is a discrete URL that you can go to to access it. I went through several pull requests to find for that view changes link and I copied the URL and here is the URL format:

http://github.com/<USER>/<REPO>/pull/<PULL>/files/<START>..<END>

For example: xwp/wordpress-develop/pull/161/files/0e8bacf..dc44bf5

The END commit doesn’t have to be the most recent commit on the pull request: it can be any commit range. This is great because sometimes I’ll want to review changes to a pull request but exclude the most recent changes, for example to not include file renames in the diff. You can include include any two commits in the pull request as the START and END.

Another key improvement in this new pull request subset compare view is that it can exclude changes introduced by merges from upstream in the diff generated. Consider, for example, making commit A then merging from master, and then making commit B. In the normal GitHub compare view, the changes will include everything from the merge commit in addition to commits A and B. In the GitHub pull request subset compare view, however, the changes from the merge commit are excluded. Maybe GitHub is doing some on the fly rebasing of the commits onto the base branch to generate these views. In terms of the commit log, it seems the normal compare view is like git diff A..B whereas the pull request subset compare view is like git diff A..B ^master. For example, “compare” these diffs:

Compare view:
xwp/wordpress-develop/compare/05bc2cb…3714ebe

Pull request subset compare view:
xwp/wordpress-develop/pull/161/files/05bc2cb..3714ebe

And again, the latter allows you to add comments whereas the former does not.

Long live this pull request subset compare view!

One thought on “Reviewing a Subset of Commits in a GitHub Pull Request”

  1. You can use use the UI:
    * click on the ‘File changes’ tab
    * open the ‘Changes from all commits’ dropdown
    * hold down shift and select the first commit you want to see
    * move the mouse down and select the final commit you want to see

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.