According to GitGuys
Remote Tracking Branches should not be modified by users (don’t set your git branch to a remote tracking branch via git checkout and then try to modify the remote tracking branch).
Unfortunately, that’s exactly what I did by accident, and committed a day’s work. And now after switching to a different branch, those commits have disappeard and cannot be found in the log of any existing branch, local or remote.
Fortunately, I still see them in .git/logs/HEAD and using git show with the hashes there gives me the code diffs, so they’re not lost completely. My questions:
- How can I get those changes into a regular branch?
- If one should not commit to a remote tracking branch, why does it not result in an error?
The commits are likely still there. You just need to find a reference that points to them.
Use
git reflogto find your last commit that you lost. Once you find that commit, usegit checkout -b <branch name> <lost commit hash>to create and checkout a branch that points to that tip.As far as the error, you should have received a message saying you were working in a headless state.