5

I need a git command that will list all of the changed files in a pull request.

I only want the file path of the changed files, no extra info.

I've tried: git diff --name-only but that doesn't return anything for a PR.

gurpsone
  • 463
  • 7
  • 17

2 Answers2

6

Pull Request is a GitHub feature and not a native Git command. However, if you have the source and target branch names, you can get the files changed using,

git diff --name-status firstbranch..yourBranchName

Showing which files have changed between two revisions

hsirah
  • 337
  • 1
  • 10
  • Just a quick note. [Pull request is a git command](https://git-scm.com/docs/git-request-pull), but it doesn't do what most people think of. – evolutionxbox Jan 17 '19 at 14:11
  • 1
    @evolutionxbox yes, but it's `git request-pull` not `git pull-request`. :-) A bit of hair-splitting to some, but to my ears, it's like the difference between "go play" and "play Go", or something like that. – torek Jan 17 '19 at 19:25
  • @torek exactly. I thought I’d include it for completeness. – evolutionxbox Jan 17 '19 at 19:33
2

You can use GitHub API. For example, https://api.github.com/repos/octocat/Hello-World/pulls/488/files

octocat is project owner, Hello-World is project name and 488 is pull request number. You can modify these values for your pull request. This request returns a JSON array of modified files and filename attribute gives you file path.

Emre
  • 933
  • 15
  • 27
  • 1
    Note that there is a limit to number of results using this API (300 files). So for large pull requests, you'll need to fetch and use git instead. – Elliot Nelson Jun 11 '19 at 13:05
  • Note: Responses include a maximum of 3000 files. The paginated response returns 30 files per page by default. source: https://docs.github.com/en/rest/reference/pulls#list-pull-requests-files – Doug Domeny Aug 06 '20 at 13:57