I was trying to push from my Git workspace up to Github but my added and committed changes didn't seem to get uploaded.
Then, doing a "git branch" I got something that looked like this :
git branch
* (no branch)
master
Foolishly, I thought I could get back into master with
git checkout master
and now my changes seem to have gone. My master branch is about a day old. And there seems no way to switch back to this (no branch).
Are my changes lost? Or is there a way to recover them?
As long as you've not done a
git gc
, then you've not lost anything. All you need to do is find it again :) What do you get with:That should show you what happened, and the id of the missing node(s).
The above answer is correct. This is what I did:
The "Oh No!" moment is this:
ca92d15d272867b63d54f96d4aa57f8ecc479cd0 is the anonymous branch that shows up as (no branch). To get back to it, just do a git checkout and your old pseudobranch is restored.
I recommend backing up your git repository before you accidentally gc it, just for peace of mind.