tags:

views:

116

answers:

2

Hi,

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

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

And how can I apply a patch in other repository?

+2  A: 

Sure, git stash show supports this:

git stash show -p
Greg Hewgill
I have a related question about apply a patch. Let's say my patch touches multiple files. Is there a way to apply the patch 'interactively'? Pick which files of the patch I should apply the patch against?Can I do that?
silverburgh
@silverburgh: I had a quick look through `man patch` and I didn't see any options for interactive patch application. However, since patch files are plain text files themselves, usually what one would do is edit the patch in a text editor to clip out the relevant parts to apply with `patch`. Alternately, if you're applying the patch into another Git repository, you could apply it all and then selectively `git checkout` files that you didn't want to change (`git checkout` with a filename throws away unstaged changes).
Greg Hewgill
A: 

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.

peritus