git create patch from unpushed commits

走远了吗. 提交于 2019-12-18 13:18:23

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/26176951/git-create-patch-from-unpushed-commits

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!