当使用 git rebase --autostash
时,git 会自动创建一个“autostash”提交,并会在 rebase 成功后重新应用它。
但如果 rebase 被中止(例如,在 Vim 中使用 :cq
当它是一个交互式 rebase 时),自动提交可能会以悬空提交结束。
Git 2.9.0
最佳答案
我发现以下内容列出了所有“autostash”提交:
git log --pretty='%cr: %h %s' $(git fsck --no-reflog \
| grep '^dangling commit' | cut -f3 -d\ ) | grep ': autostash$'
然后您可以使用提交哈希来取回提交,例如使用 git show
或 git cherry-pick
。
输出看起来像这样:
Checking object directories: 100% (256/256), done.
2 minutes ago: 7a50bcb On improve-moving-out-of-zoomed-tmux-pane: autostash
22 minutes ago: 9c504af On pr-123: autostash
5 weeks ago: f216b45 On look-for-vim-with-pgrep-ps: autostash
9 weeks ago: f405faa On look-for-vim-with-pgrep-ps: autostash
10 weeks ago: 28ddead On look-for-vim-with-pgrep-ps: autostash
关于git - 你如何从 "autostash"获得丢失的 `git rebase --autostash` 提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37845799/