Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git create patch from unpushed commits

Tags:

git

patch

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?

like image 627
Kosmotaur Avatar asked Oct 03 '14 10:10

Kosmotaur


People also ask

How do you create a patch from pushed commit?

Click on latest commit. Add . patch at the end of this url . So the modified url looks like: https://github.com/xyz/lmn-ms/tree/branch_name.patch.

How do I create a patch in git?

To create a patch file from one commit to other i.e a patch file in which changes include all the commits from starting commit and end commit. It is done by git diff starting-commit-sha ending-commit-sha myPatch. patch, where “myPatch” is the patch name and the starting and ending sha of the commits are included.


2 Answers

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.

like image 168
cfstras Avatar answered Oct 21 '22 17:10

cfstras


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.

like image 28
VonC Avatar answered Oct 21 '22 18:10

VonC