How to apply a patch created using git format-patch?

I have 2 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 this patch to another repository?

+165
git patch
Feb 12 2018-10-12T00
source share
6 answers

Note. First you can see what your patch will do:

First statistics:

 git apply --stat a_file.patch 

Then a trial run to detect errors:

 git apply --check a_file.patch 

Finally, you can use git am to apply your patch as a commit: it allows you to sign the applied patch.
This may be useful for future reference.

 git am --signoff < a_file.patch 

See an example in this article :

In your git log, you will find that the commit messages contain a "Signed" tag. This tag will be read by Github and others to provide useful information on how the commit ended up in code.

Example

+241
Feb 12 2018-10-12T00
source share
 git apply name-of-file.patch 
+117
Feb 12
source share

Or if you kick him with an old school:

 cd /path/to/other/repository patch -p1 < 0001-whatever.patch 
+31
Feb 12 2018-10-12T00
source share

If you want to apply it as a commit , use git am .

+19
Feb 12 2018-10-12
source share

First you should notice the difference between git am and git apply

When you use git am you usually want to apply a lot of patches. Therefore, you should use:

 git am *.patch 

or simply:

 git am 

Git will automatically find patches and apply them in order ;-)

UPD
Here you can find how to generate such patches.

+15
Sep 20 '18 at 6:23
source share

If you use the JetBrains IDE (for example, IntelliJ IDEA, Android Studio, PyCharm), you can drag the patch file and place it in the IDE, and a dialog box displays the contents of the patch. All you have to do now is click "Apply Patch" and a commit will be created.

+11
May 14 '18 at 12:00
source share



All Articles