git历史搞砸了

问题描述

我试图进行基础调整,以将提交合并到一个提交中,但是我最终编写了更多的提交,现在所有的工作都花了很多时间。

这是树: 在运行git status时,我得到了

On branch master
Your branch is up to date with 'origin/master'.

Last commands done (5 commands done):
   pick 49147e5 squash
   pick 2c48387 Commit 
  (see more in file .git/rebase-merge/done)
Next commands to do (13 remaining commands):
   pick fddd4c7 commit 
   pick 5f01f80 commit 
  (use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch 'master' on '1550461'.
  (use "git commit --amend" to amend the current commit)
  (use "git rebase --continue" once you are satisfied with your changes)

nothing to commit,working tree clean

运行git log --oneline时,我得到:

Merge branch 'master' of .....
49147e5 squash
0310431 commit 4 which was PR
d4be53f commit 6
ea24a2d commit 5
1550461 commit 3
fc8115a commit 2
212138a commit 1
72d8fff Merge pull request #64 from branch 1
c5ad199 commit 14
2a6ceaf commit 13
6660dbf commit 12
b6c863e commit 11
88788e6 commit 10
5bbe8a7 commit 9
9731810 commit 8
1e4ac6b commit 7
ce3817c Merge branch 'master' of .... into branch 1
ec4c3e9 commit 6
5b8900b commit 5
d10eec9 commit 4 which was PR
5f01f80 commit 3
fddd4c7 commit 2
02ebbc8 Merge branch 'master' of ....into branch 1
3995cf2 pr changes v2
2c48387 commit 1

我如何搞砸: 从72d8fff开始,我做了git rebase -i HEAD~7 or 8git pull,然后是git push。我想将squash之后的所有提交d10eec9合并为一个提交,但是我认为我最终还是在HEAD上书写。

我当时想先做git reset --hard 72d8fff,然后再做git push origin HEAD --force,这将使我回到最初的起点。
请保存。

解决方法

带我回到起点。

在本地,您可能会看到git reflog,它将列出分支的提示,并且其他引用在本地存储库中已更新。

您将在重新定位之前找到HEAD所指的
如果您reset --hard进行该提交,则将返回到重新设置基准之前。
您还可以将该提交与ORIG_HEAD and reset on that commit进行比较(如果您没有进行其他任何变基)。

想法仍然存在:首先在本地恢复您的历史记录,然后再次压缩您的最后一次提交(这次是without rebase,but using git reset --soft),并在本地存储库的状态令人满意时强制推送。