恢复提交修改期间丢失的提交

Recover commit lost during commit amend

我猜错了

昨天我创建了一个新分支(feature/crud-suppliers),然后昨天和今天我在那个分支上工作。 30 分钟前,在我完成更改后,我添加了修改后的文件并做了一个 git commit --amend --no-edit 然后我记得我之前没有提交任何东西,所以我想在提交中添加一条消息。

我认为使用 git rebase -i HEAD~2 我可以进入并更改消息,但提交不存在,所以我只是按下退出 ctrl+X 并注意到它完成了变基..

在那之后,我的编辑消失了,几分钟前,我推送了所有内容以检查我是否可以在 github 上找到编辑,但没有成功。

我尝试了 git reflog 但是在 rebase 之前检查哈希没有显示我的编辑。

这是我的 git reflog:

637b687 (HEAD, master) HEAD@{0}: checkout: moving from feature/crud-suppliers to 637b687
a55e9d9 (origin/feature/crud-suppliers, feature/crud-suppliers) HEAD@{1}: checkout: moving from 3f5931ac661a4d4ee983fe0a173ae309a874be83 to feature/crud-suppliers
3f5931a HEAD@{2}: checkout: moving from 8dd9857224adf665df1d5d981c067d6068c3bea6 to 3f5931a
8dd9857 HEAD@{3}: checkout: moving from feature/crud-suppliers to 8dd9857
a55e9d9 (origin/feature/crud-suppliers, feature/crud-suppliers) HEAD@{4}: checkout: moving from feature/crud-products to feature/crud-suppliers
9ed4250 (origin/feature/crud-products, feature/crud-products) HEAD@{5}: checkout: moving from develop to feature/crud-products
069daa3 (origin/develop, develop) HEAD@{6}: checkout: moving from feature/crud-suppliers to develop
a55e9d9 (origin/feature/crud-suppliers, feature/crud-suppliers) HEAD@{7}: rebase -i (finish): returning to refs/heads/feature/crud-suppliers
a55e9d9 (origin/feature/crud-suppliers, feature/crud-suppliers) HEAD@{8}: rebase -i (start): checkout HEAD~2
a55e9d9 (origin/feature/crud-suppliers, feature/crud-suppliers) HEAD@{9}: checkout: moving from 3f5931ac661a4d4ee983fe0a173ae309a874be83 to feature/crud-suppliers
3f5931a HEAD@{10}: checkout: moving from a55e9d98dc253dfb72461e7f4ef07dc815df0400 to 3f5931a
a55e9d9 (origin/feature/crud-suppliers, feature/crud-suppliers) HEAD@{11}: checkout: moving from feature/crud-suppliers to a55e9d9
a55e9d9 (origin/feature/crud-suppliers, feature/crud-suppliers) HEAD@{12}: rebase -i (finish): returning to refs/heads/feature/crud-suppliers
a55e9d9 (origin/feature/crud-suppliers, feature/crud-suppliers) HEAD@{13}: rebase -i (start): checkout HEAD~2
a55e9d9 (origin/feature/crud-suppliers, feature/crud-suppliers) HEAD@{14}: rebase -i (finish): returning to refs/heads/feature/crud-suppliers
a55e9d9 (origin/feature/crud-suppliers, feature/crud-suppliers) HEAD@{15}: rebase -i (pick): CRUD employees
3f5931a HEAD@{16}: rebase -i (pick): Added new ways to retreive company informations
8dd9857 HEAD@{17}: rebase -i (pick): Created company user views
faedafc HEAD@{18}: rebase -i (pick): Changed email link to reset password
9b54992 HEAD@{19}: rebase -i (start): checkout HEAD~2
b69bfb0 HEAD@{20}: commit (amend): Merge pull request #11 from alebuffoli/feature/crud-employees
069daa3 (origin/develop, develop) HEAD@{21}: checkout: moving from feature/crud-products to feature/crud-suppliers


更新

下面建议的方法有效,但事实上,在收到关于这个问题的任何回复之前,我能够使用编辑器上的历史记录功能恢复所有丢失的更改 (Pycharm),所以我想如果你处于类似情况并且无法使用以下方法恢复更改。

git 还保留了各个分支的日志:运行

git reflog feature/crud-suppliers

仅查看移动该分支的操作​​。


默认情况下:git rebase 完全删除合并提交。如果您的更改存储在提交 Merge pull request #11 from ... 中,那么 运行ning git rebase HEAD~2 将丢弃该提交。

您可以使用 -r|--rebase-merges 来保留它们。