Skip to content

Detached HEAD

一句话解释

Detached HEAD 平均值 HEAD 点 directly 到提交相反的 分支 — 提交你 制作将 不 belong 到任何分支 and 能是 lost.

用大白话说

通常, HEAD 点到 分支 name, and 分支点 到提交. 当你 git checkout <commit-hash> or git checkout <tag>, HEAD points directly to the commit — this is "detached HEAD."

In detached HEAD state, you can view and even edit files, but any commits you make will not belong to any branch. If you switch to another branch, those commits become unreachable and may be garbage collected (lost permanently).

To save commits made in detached HEAD, create a branch from the current position: git 分支 <name> then git checkout <name>. Or use git checkout -b <name> to create and switch in one step. If you have not committed anything, just git checkout <分支> to return to normal.

示例

bash
# Detach HEAD by checking out a commit
git checkout abc123
# HEAD is now at abc123 (detached)

# Save commits made in detached state
git checkout -b fix-from-abc123

# Or just return to a branch if no commits were made
git checkout main

检查 out 提交 detaches HEAD. 创建分支到 保存任何提交.

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表