git branch (no branch)

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

Upvotes: 8

Views: 4540

Answers (1)

mamapitufo
mamapitufo

Reputation: 4810

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.

Upvotes: 12

Related Questions