I have two local git repositories, both pointing to the same remote repository.
In one git repository, if I do git format-patch 1
, how can I apply that patch to the other repository?
2022-02-18
I have two local git repositories, both pointing to the same remote repository.
In one git repository, if I do git format-patch 1
, how can I apply that patch to the other repository?
Note: You can first preview what your patch will do:
First the stats:
git apply --stat a_file.patch
Then a dry run to detect errors:
git apply --check a_file.patch
Finally, you can use git am
to apply your patch as a commit. This also allows you to sign off an applied patch.
This can be useful for later reference.
git am --keep-cr --signoff < a_file.patch
As noted by riverofwind in the comments:
Don't forget if you have
autocrlf=false
for Windows only development you'll need to pass--keep-cr
toam
to keep those CRLFs
See an example in this article:
In your git log, you’ll find that the commit messages contain a “Signed-off-by” tag. This tag will be read by Github and others to provide useful info about how the commit ended up in the code.