0

I intended to squash a commit but accidentally missed a step and deleted a commit - can I get it back

git rebase -i HEAD~2

Then on the line with the commit I wanted to squash I deleted the line then I did :wq

Then my work disappeared

Can I get the commit back?

I have tried git reflog but I can't see the commit

DumbDevGirl42069
  • 891
  • 5
  • 18
  • 47
  • 1
    You can use the reflog to restore the branch on the commit where it was before the rebase then run the rebase again. – axiac Aug 15 '18 at 08:30
  • 1
    Possible duplicate of [Undoing a git rebase](https://stackoverflow.com/questions/134882/undoing-a-git-rebase) – mkrieger1 Aug 15 '18 at 08:49
  • In the reflog, you don't have to search for the commit you've accidentally removed, but for the previous tip of the branch (that still included the commit). – mkrieger1 Aug 15 '18 at 08:52

1 Answers1

1

Yes, you can get it back by going back to a checkout of a commit with history that included the commit you've lost.

So use reflog to find the point your branch was at before the rebase -i and check out that revision, then check git log for the last few commits.

Rup
  • 33,765
  • 9
  • 83
  • 112