62

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?

Patrick Sanan
  • 2,146
  • 1
  • 23
  • 25
Rishi
  • 3,359
  • 8
  • 34
  • 54

2 Answers2

78

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,557
  • 21
  • 13
  • 1
    Btw, by patch file do you mean something like what `git format-patch` produces? – fajran Jan 31 '12 at 12:10
  • 1
    yes 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
  • 2
    You 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
53

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,146
  • 1
  • 23
  • 25