I wasn't aware that I was on a detached head state and pushed the changes made to the branch that I think I was able to checkout (branch: layout), later did I know when I checkout my branch, changes made on detached state was lose. Is it possible I am going to retrieve the latest pushed I made on which I was on a detached state?
Asked
Active
Viewed 91 times
1 Answers
0
git reflog
is the answer!
https://www.atlassian.com/git/tutorials/rewriting-history/git-reflog
In the reflog, find the HEAD which you didn't push (mine was HEAD@{5}).
See the changes you made in your detatched head with git show HEAD@{5}
.
Then, from the reflog, copy the SHA recorded before you left your detached head e.g.
8928397 (sep_val_set) HEAD@{5}: checkout: moving from 89283979c4b30a8427dd6a6fe24e06f6136c86b5 to sep_val_set
Checkout this SHA:
git checkout 89283979c4b30a8427dd6a6fe24e06f6136c86b5
and save your changes in a new branch: git switch -c new-branch
-
They are also safe without being pushed, but just commited, except you are working in the constant danger that your machine can be destroyed. Are you working an explosive mine of some sort? – Binarian Nov 08 '21 at 12:52