Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I recover a lost commit in Git?

Tags:

git

First, got "your branch is ahead of origin/master by 3 commits" then my app has reverted to an earlier time with earlier changes.

How can I get what I spent the last 11 hours doing back?

like image 865
Elias7 Avatar asked Apr 11 '12 03:04

Elias7


People also ask

How do you recover a commit?

The first step to recovering your lost commits is to recover the list of all your previous commits and actions done on the repository. Note: Keep in mind that the given commit hashes and signatures may differ from that of your local repository. Replace all relevant information with the info corresponding to your log.

How do I revert lost Changes in git?

If you are using any JetBrains software, right click and go to "Local History > Show History". From here, you should see a list of local edit history separate from the Git history. You can choose any version to revert to.

How do you undo delete commit?

To restore it, we can simply run a hard reset to the commit we want to take. In my case, I will need to run git reset --hard f52ee7b . Hooray! After doing all of these, you finally can restore your deleted commit.


1 Answers

git reflog is your friend. Find the commit that you want to be on in that list and you can reset to it (for example:git reset --hard e870e41).

(If you didn't commit your changes... you might be in trouble - commit early, and commit often!)

like image 104
Amber Avatar answered Sep 18 '22 15:09

Amber