tags: - git categories: - informational comments: true
Create patch files for last X commits in in one git repo and apply them to another repo
mkdir /tmp/dir1
cd /tmp/dir1
git init
echo 'file one' > file1
git add file1
git commit -m file1
git push
echo 'file two' > file2
git add file2
git commit -m file2
git pushgit format-patch -2git format-patch -2 --stdout > file1-file2.patchmkdir /tmp/dir2
cd /tmp/dir2
git initcp ../dir1/000* .
ls
0001-file1.patch  0002-file2.patchgit am 0001-file1.patch
Applying: file1
applying to an empty historygit am 0002-file2.patch
Applying: file2mkdir /tmp/dir3
cd /tmp/dir3
git init
Initialized empty Git repository in /tmp/.git/cp ../dir/file1-file2.patch .git am file1-file2.patch
Applying: file1
applying to an empty history
Applying: file2https://www.ivankristianto.com/create-patch-files-from-multiple-commits-in-git/