Saturday, September 10, 2011

Recover lost commits in GIT

Recover lost commits in GIT:
It's a big day for me!!…I am working with GIT from last 5 days and due to some or other reason I could not push my changes to a central repository.
Generally the process I follow is commit, fetch, rebase and push paradigm everyday to make sure that my workspace is clean and latest. But, today I couldn’t go through complete process due to “fatal: malloc, out of memory “issue while doing the rebase. In the process I lost few commits but I am not sure what had happened.
I tried different options and finally I could manage to recover my lost commits with the following approach.
Please find the screenshot for memory issue.


GIT provides a greater flexibility and it manages commits as a snapshot.  Even though git status command is not saying anything about your commits but it will be there somewhere in your local repository.
Here you go...
Step 1: Check git reflog to see all your commits.
Ø  Git  reflog show

This will show all commits which you have done in your local repository including your lost commits.
Every commit will have a hash id, identify the hash id for your lost commit.
Ex:  Here, my lost commit id is “85123ef”.
Step 2:  Confirm your commit
Ø  Git  show  85123ef
This will clearly show you the description and change id of your commit.

Step 3:  Do checkout for your hash id.
Ø  Git  checkout   85123ef
This will recover your lost commit and take you back to where we were at the beginning.





No comments:

Post a Comment