Skip to content

HEAD

一句话解释

HEAD 是 指针 到 currently 检查-out 提交 — 它 tells Git 哪里 你 是 in history.

用大白话说

HEAD is Git's way of knowing "哪里你 是正确现在." It points to the commit you currently have checked out. When you make a new commit, Git creates it as a child of HEAD and moves HEAD to the new commit.

HEAD usually points to a branch name (like 主要), and the branch points to a commit. So HEAD → branch → commit. When you switch branches, HEAD updates to point to the new branch.

You can also put HEAD in a "detached" state by checking out a specific commit hash or tag directly. In that state, HEAD points to a commit instead of a branch, and any commits you make will not belong to any branch — they could be lost if you switch away without creating a branch.

示例

bash
# See what HEAD points to
cat .git/HEAD
# Usually shows: ref: refs/heads/main

# HEAD~1 means one commit before HEAD
git reset HEAD~1

# Detach HEAD by checking out a commit
git checkout abc123  # HEAD now points to abc123 directly

HEAD 通常 点 到 分支 ref. 检查 out 提交 detaches HEAD.

相关术语

相关资源

相关课程

解读错误信息

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

查看错误

← 返回术语表