Reputation:
I am new to Git and I think I don't know what I am doing.
I was editing a bunch of files including new ones. Since there were lots of changes, I wanted to commit and push them before losing my work.
So I used:
git add .
git commit -m "Blablabla"
With the following answer:
[detached HEAD b5c9786] Blablabla
29 files changed, 794 insertions(+), 265 deletions(-)
Then:
git push
With the answer
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use
git push origin HEAD:<name-of-remote-branch>
I realized that I forgot to go back to the feature branch last time I did a pull, so I switched to the feature branch.
git branch feature
Which obviously loaded the state when it was after last push.
Before I panic and do something stupid, my last commit should be somewhere locally in the .git
folder right?
I have the following files:
COMMIT_EDITMSG
HEAD
config
hooks
info
objects
refs
FETCH_HEAD
ORIG_HEAD
description
index
logs
packed-refs
COMMIT_EDITMSG
and HEAD
have timestamp around my last commit.
Upvotes: 2
Views: 2934
Reputation: 1326982
I already left the detached branch and I don't know how to get back to that detached branch
That is where git reflog
comes in.
If you had committed before leaving the detached HEAD, you will find your commit listed in the reflog.
You can then git cherry-pick
it, and apply it on your current branch.
Upvotes: 4