Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't git format-patch work for stashes?

If I run

git format-patch -1 stash@{0}

git returns silently without creating any file. Why does this happen? How can I save a stash in a format compatible with git am?

like image 841
UncleZeiv Avatar asked Apr 10 '26 11:04

UncleZeiv


2 Answers

This seems to be because the stash commit is represented as a merge (between its parent and the index state at the time), and format-patch on a merge commit does nothing.

If you say

git format-patch stash@{0}{,^}

then it will spit out patches between the stash and each parent.

For illustration, this is what the stash looks like:

*   99aedb8 (refs/stash) WIP on master: 668ff36 initial commit
|\  
| * 6b8d77f index on master: 668ff36 initial commit
|/  
* 668ff36 (HEAD, master) initial commit
like image 139
Josh Lee Avatar answered Apr 12 '26 03:04

Josh Lee


You could try

git stash show -p > ~/Desktop/stash.patch

This will generate a patch file on your desktop for the latest patch and the original parent.

Described in the documentation of git-stash under the show option

like image 37
Abizern Avatar answered Apr 12 '26 03:04

Abizern



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!