How to recover deleted commit?

Asked

Viewed 907 times

5

Consider the following story:

  1. In the local repository I commit A and B.
  2. I pushed to the repository on the server.
  3. I went back to the local repository and made changes.
  4. I removed commit B from the local repository (using the command below) before committing the new changes:
git reset --soft HEAD~

How do I recover the removed commit from the local repository so that the history matches the server repository and without losing the changes who have not yet been committed?

  • 2

    git reflog to list all commits (including floating state), and git merge [SHA1] to bring it back to the repository.

  • @Onosendai Yes, that was it, solved the problem and I haven’t lost my changes. Please add an answer to accept it as sure. Thank you.

  • @Filipemoraes feel free to implement the answer describing your process and accept it. And I’m glad it worked out for you. =)

1 answer

1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.