I have two tags in my git in same branch. There are at least 5-6 commits between them. How can I create a single patch between the two tags so that it can be applied to a GitHub repo?
Asked
Active
Viewed 5.5k times
3 Answers
86
You can create a single diff (patch) between two tags using the following
$ git diff tag1 tag2 -- > the-patch.diff
Replace tag1
and tag2
to the tags you want.

fajran
- 2,769
- 22
- 13
-
1Btw, by patch file do you mean something like what `git format-patch` produces? – fajran Jan 31 '12 at 12:10
-
1yes i need a patch file like [git format-patch] command produces.Can you tell me how this work between two tags. – Rishi Feb 02 '12 at 05:42
-
2You can squash those commits into one commit using `git rebase`. After you have that one commit, you can use `git format-patch` to create the patch file of it. – fajran Feb 03 '12 at 09:58
-
Does it matter the order of tag1 and tag2? I suspect it does – KansaiRobot Mar 01 '23 at 09:42
54
You can create a single patch for multiple commits by using the --stdout
option and directing the output to a file:
git checkout tag2
git format-patch tag1 --stdout > patch1to2.patch

Patrick Sanan
- 2,375
- 1
- 23
- 25
-
1
-
2This works well, but you have to be aware that it actually adds the patches one after another in the output file (to keep the commits etc...), it does not generate a single diff between the two versions. – Louis Caron Oct 21 '22 at 07:18
0
If you want multiple patches, then you can apply below command
$ git format-patch tag1..tag2

Ronak Patel
- 130
- 1
- 10