I'm have a problem with git resulting from an attempt at fixing another problem. I have lost some recent commits I have made. There was a merge commit and another that I had not yet pushed to the remote repository.
I did git push
. It output fatal: You are not currently on a branch.
. This is strange, as my local branch has the same name as a remote one. I did a git push
just a few hours ago successfully.
I found a page on Stack Overflow that said I should do git checkout origin:remote-branch-name
in such a situation. So I did. Here was the output:
Warning: you are leaving 1 commit behind, not connected to
any of your branches:
This is certainly not what I wanted to do.
I can still see my latest commits by doing git reflog
. After the last time I successfully pushed, I did git pull origin --rebase
because there were diverging branches at that time which I then resolved. I only made one more commit since then.
How do I get my local branch to the state it was in before I did git checkout origin:remote-branch-name
? The only thing that should be different is that the head should be attached.
I much prefer a process that doesn't make any new commits. I want the commit history to be as it was.