Reputation: 317
I have on my git 2 branches, master and SSL.
While I thought I was on master branch, I was actually detached. I pushed the changes to HEAD, then checkout to SSL branch and merged it.
When I did that, I found out that the changes committed to the master were no present on any branch and I couldn't see them.
Is there a way to restore the lost commits?
Running git reflog -n 20
:
e4a206b HEAD@{0}: checkout: moving from SSL to master
94e0f8d HEAD@{1}: checkout: moving from master to SSL
e4a206b HEAD@{2}: checkout: moving from SSL to master
94e0f8d HEAD@{3}: reset: moving to 94e0f8d
18aedb9 HEAD@{4}: checkout: moving from master to SSL
e4a206b HEAD@{5}: checkout: moving from e4a206b20456d004b5ad19bb859e15f481df9b90 to master
e4a206b HEAD@{6}: checkout: moving from SSL to master^0
18aedb9 HEAD@{7}: checkout: moving from master to SSL
e4a206b HEAD@{8}: checkout: moving from e4a206b20456d004b5ad19bb859e15f481df9b90 to master
e4a206b HEAD@{9}: checkout: moving from master to master^0
e4a206b HEAD@{10}: checkout: moving from d8b6feee2ae2595872d62ca2b25c01263b3bf74b to master
d8b6fee HEAD@{11}: merge SSL: Merge made by the 'recursive' strategy.
94e0f8d HEAD@{12}: commit: Support for os and badge count for ios
e4a206b HEAD@{13}: checkout: moving from 18aedb908898083d8b9d6941ec59f981950a3846 to master^0
18aedb9 HEAD@{14}: checkout: moving from bc071caacff35fca304aae97804fd9070d92913f to SSL^0
bc071ca HEAD@{15}: commit: Added support for sell option
e4a206b HEAD@{16}: checkout: moving from 18aedb908898083d8b9d6941ec59f981950a3846 to master^0
18aedb9 HEAD@{17}: checkout: moving from e4a206b20456d004b5ad19bb859e15f481df9b90 to SSL^0
e4a206b HEAD@{18}: checkout: moving from SSL to master^0
18aedb9 HEAD@{19}: commit: SSL
I have done a hard reset to the commit I wanted, It is still missing a file (I really don't know how).
Upvotes: 0
Views: 122
Reputation: 951
Based on git reflog
, it looks like you ran git reset
at 94e0f8d HEAD@{3}
.
You should be able to recover any committed work by simply checking out the commit before the reset: git checkout HEAD@{4}
One last thought: when you receive a "detached HEAD" notification, run git status
for some useful guidance:
You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new-branch-name
HEAD is now at 81f96ab... some commit msg
Upvotes: 1