你如何从`git rebase --autostash`中获得一个丢失的"autostash"提交

blu*_*yed 4 git rebase

使用时git rebase --autostash,git会自动创建一个"autostash"提交,并在成功重组后重新应用它.

但是如果重定位被中止(例如,:cq当它是交互式rebase时在Vim中使用),autostash-commit可能最终会成为悬空提交.

Git 2.9.0

blu*_*yed 10

我找到以下内容列出所有"autostash"提交:

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

然后,您可以使用提交哈希来获取提交,例如使用git showgit 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
Run Code Online (Sandbox Code Playgroud)

  • Rebase 将 autostash 的哈希值填充到 `.git` 中的“状态目录”(rebase 脚本中的 `$state_dir`;参见 `$(git --exec-path)/git-rebase`、`apply_autostash` 函数,大约第 160 行)。假设您正在处理 Git 错误并且此状态目录已消失:一旦您获得 ID,请使用“git stash store”将其转换为常规存储(请参阅相同的代码,大约在第 167 行)。 (2认同)

Von*_*onC 4

Git 2.10(2016 年第 3 季度)应该完全避免这个问题。

请参阅帕特里克·斯坦哈特 (Patrick Steinhardt )的提交 33ba9c6(2016 年 6 月 29 日)。(由Junio C Hamano 合并 -- --提交 5eb1e9f中,2016 年 7 月 13 日)pks-t
gitster

rebase -i:中止时恢复自动存储

当我们中止交互式变基时,我们通过调用来执行此操作die_abort,它会通过删除变基状态目录来清理我们之后的情况。
但是,如果用户请求使用自动存储功能,则状态目录还可能包含对自动存储的引用,该引用现在将被删除。

通过尝试在 中重新应用自动存储来解决该问题die_abort
这也将通过将自动存储记录在用户可见的存储中来处理自动存储不再完全应用的情况。