Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recover commit from 'detached head state'?

Tags:

I checked out another branch with updates then made a few changes, switched back to the main git and now the changes disappeared! Can I get them back? the terminal was basically:

$ git commit [detached HEAD 7c09e17] Fixed some stuff   files changed, insertions(+), deletions(-) $ git push master fatal: 'master' does not appear to be a git repository fatal: The remote end hung up unexpectedly $ git checkout master Previous HEAD position was 7c09e17... Fixed some stuff Switched to branch 'master' $ git merge theother/directory 
like image 695
NoBugs Avatar asked Jan 27 '12 22:01

NoBugs


People also ask

How do you recover from a detached head state?

It just means you are not currently attached to any branch, and as a result, your HEAD is detached. If you want to keep the changes you made while in the detached HEAD state, you can solve this problem with three simple steps: creating a new branch, committing the changes, and merging the changes.

How do you go back to a previous commit on git?

To view the previous commits, use the git log –-oneline command. This provides the commit details.


1 Answers

Assuming you're still on master:

git merge 7c09e17 

should be enough. git is usually good about telling you the commit IDs, if you watch the terminal.

like image 182
Matthew Flaschen Avatar answered Oct 27 '22 21:10

Matthew Flaschen