accidentally rolled back to a previous commit in git
I am new to Git and not sure what I did wrong. I have bunch of branches along side master for example – filling-layout, data-upload, sign-in-out etc. I had moved on to a new branch, when I had to change something in my layout. So I thought it would be better to go back to filling-layout branch and make the changes there. So I typed in
git checkout filling-layout and that erased a bunch of things that I had in the layout and its back to a previous version and all my changes disappeared. I thought I had committed filling-layout after all my changes and uploaded it to github and heroku.
- Any idea how I can get it back?
- Also can anyone explain why this could happen?
- What are the best practices when you have to make a small change that
could potentially go into the previously committed branch?
- Is it better to make a new branch or you can checkout the existing
branch to make the change.
One Solution collect form web for “accidentally rolled back to a previous commit in git”
Try checking out the previous branch.
This might work
git checkout -
It will try to checkout the branch you were on before the current one (analogous to
Once you have committed your changes in git it is very difficult to loose them. Checking out a branch will change the working tree to match what is in that branch, but switching back will restore the state of the working tree to that of the previous branch.
Another way to find previous commits is by using
git reflog. That will list what commits HEAD has been at, and using the hash you can checkout any of those.