问题
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
回答1:
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.
回答2:
I couldn't find a way to see just the list of changed files in GitHub (i.e. without the diff and comments), but it can be done with this one-liner in the browser console:
Array.from(document.getElementsByClassName('js-details-target')).forEach((e) => {e.click();})
This will collapse all the diff blocks leaving only the filenames.
回答3:
Google search sent me here though it is slightly different question.
This question [details] has command-line. However, I needed the list of files, its ok if I can see in GUI
Here a way to see list of files in GUI:
open the pull request
click on the [Files changed] tab
Conversation 0 Commits 3 [Files changed] 8
click on drop down after 'n files' in the below line of [Files changed]
Changes from all commits v ... [8 files v] ... +638 −266
(click on the v, drop down, after files in the above line)
回答4:
Chrome console...
Note: This will break if Github changes the tags/classes/IDs in the page.
const fileElems = document.querySelectorAll('#files div.file-info a.link-gray-dark');
const filePaths = [];
for (let a of fileElems) {
filePaths.push(a.title);
}
const filePathsStr = filePaths.join('\n');
console.log(filePathsStr);
copy(filePathsStr);
console.log('Copied to the clipboard as well 😁');
来源:https://stackoverflow.com/questions/25071579/list-all-files-changed-in-a-pull-request-in-git-github