Accidentally, I have lost my iRobot creation project changes, very important. I will show you the mistake happen and how to avoid same situations. Also best practices we can consider while working with GIT with large user contribution.
This is my old git repo.
- What went wrong and the reason?
I was working on my local 'dev' branch which is link with remote repo. I keep on commit my changes at a time so that I can understand RCA in case of an exception. As I have already committed my changes I checkout for 'origin/dev'. (It has happen for whatever the reason)
I noted all of my changes has been reverted. 'God, what went wrong? I totally lost.' The reason is that I have converge dev with origin/dev, which is lost my local changes even I have commited.
- After checkout origin/dev
- Recovering commits with "git reflog" and reset
Thanks to "git reflog" tool, I able to recover my lost commits.
- Retrieving a branch of an earlier state.
Now, see the history and the mistake I have done. "git reflog" gives you a good history about what has been done to head of your branches. In this case, head is reset to origin/dev at "8d29594". I need to rest head to the commit "09a3f2a" which is my last commit of the changes.
Here we go !!!! I pointed head to the correct commit. Also note that I need checkout the branch since I am on the right branch "dev". If history shows different checkout branch, you need to checkout to the right branch first.
Ok. Finally here my local settings look like after pushing.
Also, keep in mind an impotent thing. If you have heavily RnD oriented thing do it in different branch then merge it with "dev". This makes less complicated other to track the changes. In above example consecutive commits are recorded in remote repo after pushing which may hard to track others of your changes.