git detached head code example
Example 1: git soft reset head
git reset --soft HEAD^
//resets head by 1
Example 2: git reset head
sudo git reset --hard Head
Example 3: git fix detached head
2388
Detached head means you are no longer on a branch, you have checked out a single commit in the history (in this case the commit previous to 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
Next time you have changed a file and want to restore it to the state it is in the index, don't delete the file first, just do
git checkout -- path/to/foo
This will restore the file foo to the state it is in the index.