Home > Enterprise >  How to fix "Head detached from <commit>"?
How to fix "Head detached from <commit>"?

Time:02-08

I checked out a previous commit in my project recently, and just noticed when I ran git status that it was returning HEAD detached from 7263532. These are my most recent two commits:

commit 8a870e8a1cb63bac7e9ec732908e54f20e841bb3 (HEAD)

commit 72635327285025d2e89962fc7ff854a8c67fdfe1 (dev-updates)

dev-updates is the name of my current branch.

I thought I had checked back out my most recent commit after checking out the previous one. I have edits in my working directory that I don't want to lose. What I want to know is, how do I fix the HEAD detached warning without losing any of my work?

CodePudding user response:

Make a temp branch. Add and commit to it. Switch to dev-updates. Cherry pick temp. Delete the temp branch. So:

git switch -c temp
git add .
git commit -mtemp
git switch dev-updates
git cherry-pick temp
git branch -D temp

CodePudding user response:

Make sure all your changes have been committed to your dev-updates branch; Then checkout your master branch:

git checkout 8a870e8a1cb63bac7e9ec732908e54f20e841bb3

And finally merge your branch in:

git merge dev-updates
  •  Tags:  
  • Related