It seems that in PR's the git diff behaves differently than what it does on my local machine. My PR has 6 commits, I would like to see the diff between the latest and previous commit but keep getting the diff for the entire PR. Is this possible in PR's on GitHub?
The command for diff I'm using: git diff --name-only HEAD^ HEAD
Local:
list modified files
.github/actions/paths-filter.yaml
.github/workflows/tests.yml
PR in Github:
list modified files
.github/actions/paths-filter.yaml
.github/workflows/tests.yml
packages/base/tailwind.config.js
packages/react/jest.config.js
CodePudding user response:
Open the single commit by clicking the link to the commit in the PR overview or select the commit from the dropdown in the top-left in the "Files changed" tab. That will show you the patch for this single commit only. Or go to the "Commits" tab and select your commit.
CodePudding user response:
After a lot of testing it turns out the HEAD in PR's in GitHub point towards an extra merge commit that GitHub injects, meaning to get the same results as my local environment I had to backtrack to the second and third commits.
I was able to use the following code in the PR to check for file changes:
first_commit=$(git log -n 1 --skip 1 --pretty=format:"%H")
second_commit=$(git log -n 1 --skip 2 --pretty=format:"%H")
echo "list modified files"
files=$(git diff --name-only $first_commit..$second_commit)
echo "$files"
Would display:
list modified files
.github/actions/paths-filter.yaml
.github/workflows/tests.yml