How do you get a lost “autostash” commit from `git rebase --autostash`

跟風遠走 提交于 2019-11-29 07:55:49

Git 2.10 (Q3 2016) should avoid that issue entirely.

See commit 33ba9c6 (29 Jun 2016) by Patrick Steinhardt (pks-t).
(Merged by Junio C Hamano -- gitster -- in commit 5eb1e9f, 13 Jul 2016)

rebase -i: restore autostash on abort

When we abort an interactive rebase we do so by calling die_abort, which cleans up after us by removing the rebase state directory.
If the user has requested to use the autostash feature, though, the state directory may also contain a reference to the autostash, which will now be deleted.

Fix the issue by trying to re-apply the autostash in die_abort.
This will also handle the case where the autostash does not apply cleanly anymore by recording it in a user-visible stash.

I have found the following to list all "autostash" commits:

git log --pretty='%cr: %h %s' $(git fsck --no-reflog \
  | grep '^dangling commit' | cut -f3 -d\ ) | grep ': autostash$'

You can then use the commit hash to get the commit back, e.g. using git show or git cherry-pick.

The output looks like this:

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!