14

I cannot push when working remotely, so I want to create a single patch from all the commits that have not yet been pushed on my develop branch to email it. How do I do that?

Kosmotaur
  • 1,686
  • 14
  • 20
  • possible duplicate of [Viewing Unpushed Git Commits](http://stackoverflow.com/questions/2016901/viewing-unpushed-git-commits) – d33tah Oct 03 '14 at 10:37
  • 5
    absolutely not, that thread only answers how to view unpushed commits, says nothing about creating a patch from them – Kosmotaur Oct 05 '14 at 20:29

2 Answers2

18

git format-patch <commit-ish> creates a patch file for every commit you made since the specified commit.

So, to export all your unpushed commits, simply put

git format-patch origin/master -o patches/

and all of them will be output into the patches/ directory.

If you want to have a single file, add --stdout:

git format-patch origin/master --stdout > patches_$(date -I).patch

This will create a file named patches_2014-10-03.patch (or another date) with all your patches in it. Beware: patch or other simple patch applications cannot cope with the produced file. It will only work with git am.


Sidenote:
An easier (and more robust) thing to do might be to keep a copy of your repo on a thumbdrive or similiar. Then set up the thumbdrive as a remote (git remote add thumb /media/thumbdrive), push your commits to it (git push thumb master) and when back at your firm, pull from the drive and push to origin.

cfstras
  • 1,613
  • 15
  • 21
  • thank you, that was exactly what I was looking for BTW, on OS X `date` turned out not to recognize the `-I` option, so I just called my patch `foo.patch`, happy days – Kosmotaur Oct 05 '14 at 20:28
  • Good to know, I was getting used to using `$(date -I)` everywhere :) – cfstras Oct 06 '14 at 08:32
5

Instead of creating a patch, you could create a bundle (meaning a file representing a git repo, from which you will be able to pull).
In your case, an incremental bundle is needed.

git bundle create ../yourRepo.bundle" --since=x.days.ago --all

Replace x by then number of days you want to put in that bundle: don't be afraid to put "too mayn" days in that repo: someone cloning from your bundle will get only the new commits, not the one he/she already had in the local repo.

A bundle is a single file, like a patch, but can be used as a Git repo: easy to copy around and easy to use (as a regular Git repo).
If your only use is to complete a local repo with commits done from a remote repo (from which you couldn't push directly), this is easier than patches.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250