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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25071579/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:17:45  来源:igfitidea点击:

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

gitgithubpull-request

提问by Alfred Xing

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.

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:

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

回答by zanerock

In general, you can list the files changed between any two commits with git diff --name-only :

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?

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:

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)

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_HEADwas branched from masterto the current FETCH_HEAD. I tested this locally, and the PR branches are cut from masterI believe it should work.

This will show you the changes between the point at which the FETCH_HEADwas branched from masterto the current FETCH_HEAD. I tested this locally, and the PR branches are cut from masterI believe it should work.

回答by laurent

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:

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.

This will collapse all the diff blocks leaving only the filenames.

回答by AdamHickey

Chrome console...

Chrome console...

Note: This will break if Github changes the tags/classes/IDs in the page.

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 ');

回答by Manohar Reddy Poreddy

Google search sent me here though it is slightly different question.

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

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:

Here a way to see list of files in GUI:

  1. open the pull request

  2. click on the [Files changed] tab

    Conversation 0 Commits 3 [Files changed] 8

  3. click on drop down after 'n files' in the below line of [Files changed]

    Changes from all commits v ... [8 files v] ... +638 ?266

  1. open the pull request

  2. click on the [Files changed] tab

    Conversation 0 Commits 3 [Files changed] 8

  3. 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)

(click on the v, drop down, after files in the above line)