0

I own the repo. A person sent a PR which I haven't merged yet. I want to see all changes from that PR as compared to my master branch in VSCode. It's similar to when you make some changes and those are in uncommitted state). How do I do it?

I followed How can I check out a GitHub pull request with git? but didn't find the answer as per my need. For instance command git pull origin pull/939/head will merge the changes instead of showing as uncommitted changes.

GorvGoyl
  • 42,508
  • 29
  • 229
  • 225

2 Answers2

1

Got it working.

So, my complete flow is:

  1. checkout PR (100) in 'detached HEAD' state
    git fetch origin pull/100/head && git checkout FETCH_HEAD

  2. show as uncommitted changes
    git reset main

  3. switch back to main branch and carry these changes
    git switch -


Also, made a handy powershell function

<# USE CASE
> gitpr
gives list of active PRs

> gitpr 12
checks out PR #12
#>
function gitpr {
  param(
    [Parameter(ValueFromRemainingArguments = $true)]
    [String[]] $prNum
  )
  
  if($prNum){
  git fetch origin pull/"$prNum"/head && git checkout FETCH_HEAD
  git reset main 
  git switch -
  echo "checked out PR: "$prNum""
  }else{
  gh pr list
  }
}
GorvGoyl
  • 42,508
  • 29
  • 229
  • 225
0

First, you must fetch the PR
git fetch origin pull/<pr_id>/head:new_branch
now you have the PR changes in new_branch
git diff new_branch ^HEAD | git apply -

  • git diff <another-branch> ^HEAD this will print a diff of the changes between the new_branch and your current branch (HEAD).
  • git apply - then this will apply those changes to the current index.
Ahmed Kamal
  • 561
  • 6
  • 17