Git rebase——abort让我所有的提交都消失了,有办法恢复它们吗



我上个月开始了我的项目,到目前为止已经提交了大约150次。

我也经常推,我最后一次推是今天早上。因此,我的工作并没有完全丢失,但我想知道是否可以进行本地恢复,以恢复我的最后一次提交(推送后(。

以下是发生的事情:

  • 今天早上,我恢复了两天前的一次提交。AFAIK,一切顺利。从那以后,我一直在努力和承诺。

  • 今天下午,我意识到我的最后两次提交可以合并。所以我尝试了git rebase --interactive。但Git的回答是:

I wonder if you are in the middle of another rebase.  If that is the
case, please try
git rebase (--continue | --abort | --skip)
If that is not the case, please
rm -fr ".git/rebase-merge"
and run me again.  I am stopping in case you still have something
valuable there.

我认为我是由于最近的恢复,所以做了git rebase --abort。我做错了。我几乎所有的提交都消失了,git日志只显示了前3个,上个月。我想从那时起我就有一个待决的重新基数。

有没有一种方法可以恢复这个重新基准——中止?

感谢您的阅读和帮助。

编辑:这是数字状态:

On branch master
Your branch is behind 'origin/master' by 147 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
Untracked files:
(use "git add <file>..." to include in what will be committed)
.vscode/
__pycache__/
main.py
venv/
nothing added to commit but untracked files present (use "git add" to track)

编辑:这是git reflog(我想回到f0b2519(:

6b634e3 (HEAD -> master) HEAD@{1}: rebase -i (abort): updating HEAD
f0b2519 HEAD@{2}: commit: Add comments in params
da4f6b7 HEAD@{3}: commit: Add comments in params
850ac42 HEAD@{4}: commit: del pygame import in params, adapt main and pygi
3415a2f HEAD@{5}: commit: Put config content in params then delete config
98a8b89 HEAD@{6}: commit: Supress 'if main' in params
72803da (origin/master) HEAD@{7}: checkout: moving from 63cb88ae8d2f1547c7d18882084c06b73d892419 to master
63cb88a HEAD@{8}: checkout: moving from master to branch2
72803da (origin/master) HEAD@{9}: revert: Revert "Move switcher in pgi.press_key()"       
3f3ccb6 HEAD@{10}: checkout: moving from branch2 to master
63cb88a HEAD@{11}: checkout: moving from branch2 to branch2
63cb88a HEAD@{12}: revert: Revert "Move switcher in pgi.press_key()"
3f3ccb6 HEAD@{13}: checkout: moving from master to branch2
3f3ccb6 HEAD@{14}: checkout: moving from branch2 to master
3f3ccb6 HEAD@{15}: checkout: moving from master to branch2
3f3ccb6 HEAD@{16}: commit: Update requirements.txt
ccc6845 HEAD@{17}: commit: Edit docstring in pygameinterface
e4632d2 HEAD@{18}: commit: Linting on config and tool

编辑:git reset-hard f0b2519像一个符咒一样工作,真是松了一口气!非常感谢大家。

Git reflog很可能是你的朋友和救世主。

引用日志或"reflogs"记录分支和其他引用的提示何时在本地存储库中更新。反射在各种Git命令中都很有用,用来指定引用的旧值。例如,HEAD@{2}表示"HEAD在两次移动前的位置",master@{one.week.ago}表示"master在本地存储库中指向一周前的位置,依此类推。有关详细信息,请参阅gitrevisions[7]。

这就是ohshitgit.com对reflog 的看法

您可以使用它来恢复您意外删除的内容,或者只是删除您试图破坏回购的一些内容,或者在错误合并后恢复,或者只是回到事情真正起作用的时候。

当我搞砸的时候,我曾多次使用reflog。

你可以回到什么地方,通过检查reflog中的特定点,这个SO答案可能会更清楚地说明问题。

最新更新