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: