48

I've been working with git for a few weeks, but now I'd like to contribute back to this open source project. I've merged my work with the latest, remote by pulling editing out conflicts and it all looks the way it should in gitk. Now I need to create a patch that is against the latest version of origin (remote) master. So I thought the following command would work:

git format-patch origin:master --stdout > 25032011.patch

but I get:

fatal: Invalid object name 'origin'.

So I've obviously got the command wrong. So how would I create a patch by comparing a specific branch on the remote with a specific local branch?

justify
  • 1,036
  • 2
  • 14
  • 26

2 Answers2

79

Use git format-patch origin/master. This creates a patch file for each commit on your checked out branch, which is not in origin/master.

To have one file instead of multiple files you can use

git format-patch master --stdout > mypatch.patch
Mohammed H
  • 6,880
  • 16
  • 81
  • 127
Rudi
  • 19,366
  • 3
  • 55
  • 77
  • cool thanks, I still seem to be be doing something wrong, I had merged the origin:master with my local:master. But when I ran `git format-patch origin/master` the resultant patch was 27MB there is no ways my additions could constitute that much code. There's some binary patching .gitignore has never seemed to work as expected(I'll take another look at excluding built jars). But the main thing is the patch shows commits where I added then later removed stuff, is it not possible to diff just the HEADS of both branches? – justify Mar 27 '11 at 15:44
  • You can use `git diff »version1« »version2«` to inspect the differences between two different versions. – Rudi Mar 28 '11 at 07:17
  • I've kinda been putting this task off. But I'd really like to know how to get git to not diff the built files. I have `*.jar` in the .gitignore but every time I create a patch it's got binary patch bit which take up alot of space - can't seem to find any immediate solutions to this checking git info resources. It's driving me crazy. – justify Apr 01 '11 at 08:21
  • 27
    To have one file instead of multiple files you can use `git format-patch master --stdout > mypatch.patch` – batigolix Dec 02 '14 at 16:30
  • @batigolix: Can you make that into an answer? – Maxwell175 May 25 '17 at 02:47
13

Use this to create one file containing all commits in your current branch that are not in the master branch:

git format-patch master --stdout > mypatch.patch
batigolix
  • 1,674
  • 18
  • 20