[edit] 实际上,最简单的方法可能是:
git commit
一种相当简单的方法,使用常用的 stash 命令,是:
git stash -k # stash your changes but keep the index
git stash # stash again (only you index)
git stash pop --index stash@{1} # restore your repo to how it was
您的顶级存储现在将拥有您的索引(并且只有您的索引)。
实际上,创建一个存储(常规存储)已经将您的索引存储在一个单独的位置。
要查看这个:运行git stash,然后运行git log --graph --oneline stash:
$ git stash
$ git log --oneline --graph stash
* f94915d (refs/stash) WIP on master: 963f4f4 Merge branch 'fork'
|\
| * f45cef3 index on master: 963f4f4 Merge branch 'fork'
|/
* 963f4f4 (HEAD -> master) Merge branch 'fork'
...
名为“index on ...”的提交包含您在运行git stash 时拥有的索引的内容。
您可以将该提交用作常规提交;如您所见,它是实际存储的第二个父级(stash^2,在我的示例中为 f94915d^2)。
git stash 有其他子命令,用于编写脚本。
例如:git stash create 将创建要存储在存储中的提交,但不会更新名为 stash 的引用或其 reflog:
$ git stash create
8bdb3b5accb08a8e16ec88a49682fcbf10d29ccf # <- you want to do something with this commit
索引的内容是{thathash}^2。所以另一种方法是:
# will create a banch 'myindex' containing your current index :
$ git branch myindex $(git stash create)^2