Skip to content

Instantly share code, notes, and snippets.

@lupyuen
Last active April 20, 2026 11:49
Show Gist options
  • Select an option

  • Save lupyuen/b1c9779482bb0c2b0c3b690f7a74e3dd to your computer and use it in GitHub Desktop.

Select an option

Save lupyuen/b1c9779482bb0c2b0c3b690f7a74e3dd to your computer and use it in GitHub Desktop.
How To Copy The Modified Files from a GitHub Pull Request

How To Copy The Modified Files from a GitHub Pull Request

Suppose we wanna copy the Modified Files from this PR:

https://github.com/lupyuen2/wip-nuttx/pull/56/files

From this repo:

https://github.com/lupyuen2/wip-nuttx/tree/gpio2

To this repo:

https://github.com/rushabhvg/nuttx/tree/gpio

Here's how:

## Download the Source `gpio2` branch to /tmp/gpio2/nuttx
cd /tmp
mkdir gpio2
cd gpio2
git clone \
  https://github.com/lupyuen2/wip-nuttx \
  nuttx \
  --branch gpio2

## Download the Destination `gpio` branch to /tmp/gpio/nuttx
cd /tmp
mkdir gpio
cd gpio
git clone https://github.com/rushabhvg/nuttx \
  nuttx \
  --branch gpio

To get a list of the Modified Files by PR, we run this:

## Get the Diff Files from the PR
pr=https://github.com/lupyuen2/wip-pinephone-nuttx/pull/56
curl -L $pr.diff \
  | grep "diff --git" \
  | sort \
  | cut -d" " -f3 \
  | cut -c3-

We will see the output:

.gitignore
arch/risc-v/src/bl808/Make.defs
arch/risc-v/src/bl808/bl808_gpio.c
arch/risc-v/src/bl808/bl808_gpio.h
arch/risc-v/src/bl808/hardware/bl808_glb.h
boards/Kconfig
boards/risc-v/bl808/ox64/configs/nsh/defconfig
boards/risc-v/bl808/ox64/include/board.h
boards/risc-v/bl808/ox64/scripts/gnu-elf.ld
boards/risc-v/bl808/ox64/scripts/ld.script
boards/risc-v/bl808/ox64/src/Makefile
boards/risc-v/bl808/ox64/src/bl808_appinit.c
boards/risc-v/bl808/ox64/src/bl808_autoleds.c
boards/risc-v/bl808/ox64/src/bl808_userleds.c

Then we copy and paste into a script like this:

(In VSCode: Use "Right-Click > Change All Occurrences" and change all Line Feeds to copy_file)

## Copy a Diff File
function copy_file {
  set -x  #  Echo commands
  cp \
    /tmp/gpio2/nuttx/$1 \
    /tmp/gpio/nuttx/$1
}

## Copy all Diff Files
copy_file .gitignore
copy_file arch/risc-v/src/bl808/Make.defs
copy_file arch/risc-v/src/bl808/bl808_gpio.c
copy_file arch/risc-v/src/bl808/bl808_gpio.h
copy_file arch/risc-v/src/bl808/hardware/bl808_glb.h
copy_file boards/Kconfig
copy_file boards/risc-v/bl808/ox64/configs/nsh/defconfig
copy_file boards/risc-v/bl808/ox64/include/board.h
copy_file boards/risc-v/bl808/ox64/scripts/gnu-elf.ld
copy_file boards/risc-v/bl808/ox64/scripts/ld.script
copy_file boards/risc-v/bl808/ox64/src/Makefile
copy_file boards/risc-v/bl808/ox64/src/bl808_appinit.c
copy_file boards/risc-v/bl808/ox64/src/bl808_autoleds.c
copy_file boards/risc-v/bl808/ox64/src/bl808_userleds.c

The Modified Files will be copied from /tmp/gpio2/nuttx to /tmp/gpio/nuttx

This is super helpful for splitting a Huge Pull Request like this:

Into Multiple Smaller Pull Requests:

@davidhamilton994

Copy link
Copy Markdown

n compañero me recomendó entrar en rodeo slot y me vinieron de lujo los bonos para gente de España que tienen ahora. Al principio tuve una racha de mala suerte frustrante y perdí varias rondas seguidas casi sin darme cuenta. Pero decidí arriesgar un poco más en una última jugada y gané un premio que me cambió el humor totalmente. Es una alternativa estupenda para despejar la mente cuando la planificación de grandes eventos te agobia.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment