fzdwx

fzdwx

Hello , https://github.com/fzdwx

About Git Detached Head

When I was making changes to my nvim configuration, I encountered a detached head branch. The main symptom was that I couldn't commit changes in Git. Since I was using lazygit, its prompts were not clear, so I thought I had committed the changes. Later, when I opened IntelliJ IDEA to see what was going on, I found a prompt about the detached head branch, but I didn't pay much attention to it at the time.

Then came the fatal mistake: I directly checked out the main branch, and all the changes I made tonight were gone.

Here's my solution:

  1. Checking git log only shows the commit history of the current branch. Ineffective
  2. Using IntelliJ IDEA's local history feature, I could only find the files, but the contents inside were blank. Ineffective
  3. Searching for solutions to detached head only provided solutions for before switching branches, which didn't apply to my situation. Ineffective
  4. Finally, I searched for all commits in Git and found git reflog, which displays the reflog history of versions. I found the commit I needed and then used git reset --hard xxx to solve the issue perfectly.

To be honest, I was a bit panicked and annoyed. If I couldn't recover the changes, I might give up on nvim.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.