3

如果我跑

git format-patch -1 stash@{0}

git 静默返回,不创建任何文件。为什么会这样?如何以兼容的格式保存存储git am

4

4 回答 4

4

这似乎是因为存储提交被表示为合并(在其父状态和当时的索引状态之间),并且format-patch在合并提交时什么都不做。

如果你说

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

然后它会在 stash 和每个父节点之间吐出补丁。

为了说明,这就是 stash 的样子:

*   99aedb8 (refs/stash) WIP on master: 668ff36 initial commit
|\  
| * 6b8d77f index on master: 668ff36 initial commit
|/  
* 668ff36 (HEAD, master) initial commit
于 2011-01-04T17:42:18.810 回答
1

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

于 2011-01-04T18:16:36.190 回答
0

我可以想到2种方法。

解决方案 1:从 stash 创建一个分支。这种方式违背了存储功能的最初目的,即避免创建单独的分支。

解决方案 2:在存储之前将跟踪文件的所有更改添加到索引中。存储后,运行

git format-patch 'stash@{0}^1'..'stash@{0}^2'

它将 HEAD 与索引进行比较(在创建存储时)。

我不确定为什么你不能只将文件未添加到索引中并运行 git format-patch 'stash@{0}^1'..'stash@{0}'

这似乎是同一件事。stash 提交对象一定有什么特别之处。在任何情况下,添加到索引都会记录存储的第二个父级(索引提交)中的更改,绕过存储提交的问题。

杂项注释: git format-patch -1对于合并提交将始终为空白(存储是合并提交的一种特殊情况)。我不完全确定这是为什么,但请参阅Git:如何为合并创建补丁?了解更多详情。

于 2011-08-16T20:42:36.607 回答
-1

如果您的文件被隐藏使用git stash -uthengit stash show -p不起作用

于 2013-10-15T19:53:52.933 回答