Now it turns out that the head is cut off/detached. i dont know what it is. How do I get it back?
Detached head means You are no longer at branch. Checked out a single commit in history (in this case, the commit before HEAD, i.e. HEAD).
If you want to delete your changes associated with the detached HEAD
You only need to checkout the branch you were on, e.g.
git checkout master
If you then change the file and want to restore the state in the index, delete the file without deleting it first.
git checkout -- path/to/foo
This will restore the file foo to the state it is in the index.
If you want to keep your changes associated with the detached HEAD
- Run
git branch tmp
- this will save your changes in a new branch calledtmp
. - Run
git checkout master
- If you would like to incorporate the changes you made into
master
, rungit merge tmp
from themaster
branch. You should be on themaster
branch after runninggit checkout master
.