I have two repositories. In one, I make changes to file ./hello.test
. I commit the changes and create a patch from that commit with git format-patch -1 HE
There is a simple solution that does not involve manual patch editing nor external script.
In the first repository (this may also export a range of commit, use -1
if you want to select only one commit) :
git format-patch --relative --stdout > ~/patch
In the second repository :
git am --directory blue/red/ ~/patch
Instead of using --relative
in git format-patch
, another solution is to use -p
option in git am
to strip n
directories from the path of the patches, as mentioned in a answer to a similar question.
It is also possible to run git format-patch --relative
without the --stdout
, and it will generate a set of .patch
files. These files can then be fed directly to git am
with git am --directory blue/red/ path/to/*.patch
.