How can I format patch with what I stash away

Viewed 61199

In git, I stash away my changes. Is it possible that I can create a patch with what I stash away? And then apply that patch in some other repository (my co-worker's)?

I know git format-patch -1, but I think that it's for what I have committed. But I am looking for the same thing for changes that I stashed away.

And how can I apply a patch in other repository?

5 Answers

Sure, git stash show supports this:

git stash show -p

So, use

git stash list

to find out the number of the stash that you want to export as a patch, then

git stash show -p stash@{<number>} > <name>.patch

to export it.

For example:

git stash show -p stash@{3} > third_stash.patch

Use

$> git stash list
stash@{0}: WIP on master: 84fx31c Merged with change to /public/
stash@{1}: WIP on master: 463yf85 FlupResource: also takes json as a query parameter

to get a list of your recently stashed stuff. Git actually creates commit objects when you stash.

They are commits like everything else. You can check them out in a branch:

$> git checkout -b with_stash stash@{0}

You can then publish this branch and you colleague can merge or cherry-pick that commit.

Related