well, i have just made a huge mistake.
I am working on a project, and thought i was working in the master branch.
So i added the files i needed, commited them and when i tried to push to origin i got
Everything is up to date
I used git branch
and got
* (no branch)
* master
So, in stress, i stashed the pending changes in (no branch) and checked out master. Now i lost all my changes, because i can't checkout the branch "that shall not be named". When i list the branches i only have
* master
The “no branch” state is called a detached HEAD. It is called this because the HEAD ref is not attached to any branch, instead it is pointing directly at a commit. To attach HEAD to a branch that points to the current HEAD commit, use git checkout -b branchname .
This can happen if your repo has 0 commits. If you make a commit, your current branch will appear when you do: git branch . Save this answer.
"Not currently on any branch" means you have a detached head, i.e. your HEAD pointer is directly referencing a commit instead of symbolically pointing at the name of a branch.
You haven't lost the changes if they were committed. You just don't have a named reference to them.
Try running git reflog
and look for a line near the top that will say something like checkout: moving from <commit-id> to master
. You can then use that <commit-id>
to create a temp branch to inspect your changes and bring them over to the master
branch:
git checkout -b temp-branch <commit-id>
You can merge this branch, or just cherry-pick the necessary commits.
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With