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

标签 git rebase

当使用 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 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

关于git - 你如何从 "autostash"获得丢失的 `git rebase --autostash` 提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37845799/

相关文章:

android - 将 Git 项目从 Eclipse 迁移到 Android Studio

git - 如何将只读的 git 克隆从 github 转换为 fork 的

ruby-on-rails - 生成 SSH key (Win/msysgit) - Ruby on Rails 教程

git - 安全的 git rebase

git - 如何自动删除取消自己的提交?

git - 像 GitHub 垃圾这样的 Web 界面是否会收集悬挂的远程 git 提交,如果没有,是否有可能获取它们?

git - 如何获取当前仓库的名称和人员/组织以用于 .gitconfig?

git - 我怎样才能 rebase 和保留 merge 并进行压缩/修复

git - 如何对一系列提交进行 git rebase -i?

Git rebase而不是merge,正确的方法是什么?