This was useful for me when we created a new branch for a new major release, but were still working on our current version as well. I cloned our repo again and kept the new project on our new branch, but also wanted to get my stashes there.
git stash show -p > patch
You'll have to specify your stash and name your file whatevery you want. Do this for as all your stashes, and you'll have patch files in your pwd.
cd /new/project/dir
git apply /old/project/dir/patchfile
git stash
If you want to include untracked files in the patch, you can use
--include-untracked
, for example to output the patch from stashstash@{2}
:There's also a counterpart option
--only-untracked
.You can also set git config
stash.showIncludeUntracked
totrue
save this trouble:git config --global stash.showIncludeUntracked true
or in
.gitconfig
: