How to create a patch without commit in Git

doglin picture doglin · Mar 21, 2012 · Viewed 41.7k times · Source

I did some search online. I know that you can use format-patch after commit, but my situation is a little different.

I want to create a patch, similar to "dpk" in SVN, so I can send it out for code review, but I don't yet want to commit it.

How can I achieve this with Git?

Answer

RayLuo picture RayLuo · Feb 24, 2014

When other guys had already given some answer which comply with git convention, the OP's question, "create a patch without commit", can be also solved in this way:

git diff > my_patch.txt

Later you can apply this patch, also without a commit, by:

git apply my_patch.txt

But if you are just working locally, a git checkout another_branch -m is good enough to bring all your current uncommit changes to that another_branch, without even patch and apply.