我从master分支检出了一个commit/branch,然后切换回master分支并写了一些内容。之后,我进行了提交,但结果是分离头状态。为什么?
以下是我的操作步骤:
- 创建一个新项目并创建git仓库。
- git add
- git commit
- 输入一些文字
- git commit
- 切换到先前的提交版本
切换回来
输入一些文字
尝试进行提交;提示出现了分离头。
IntelliJ IDEA控制台显示:
17:08:58.143: cd C:\Users\jiahao\IdeaProjects\testtt\src
17:08:58.143: git init
Initialized empty Git repository in C:/Users/jiahao/IdeaProjects/testtt/src/.git/
17:09:16.331: cd C:\Users\jiahao\IdeaProjects\testtt\src
17:09:16.331: git -c core.quotepath=false add --ignore-errors -- C.java
17:09:24.407: cd C:\Users\jiahao\IdeaProjects\testtt\src
17:09:24.407: git -c core.quotepath=false commit --only -F C:\Users\jiahao\AppData\Local\Temp\git-commit-msg-0.txt -- C.java
[master (root-commit) 22d1c79] first commit
1 file changed, 6 insertions(+)
create mode 100644 C.java
17:09:38.060: cd C:\Users\jiahao\IdeaProjects\testtt\src
17:09:38.060: git -c core.quotepath=false commit --only -F C:\Users\jiahao\AppData\Local\Temp\git-commit-msg-0.txt -- C.java
[master 69084f3] second commit
1 file changed, 1 insertion(+)
17:09:44.136: cd C:\Users\jiahao\IdeaProjects\testtt\src
17:09:44.136: git -c core.quotepath=false checkout 22d1c7919eab50925411d9bbb8a9ad1575608c27
Note: checking out '22d1c7919eab50925411d9bbb8a9ad1575608c27'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at 22d1c79... first commit
17:09:46.576: cd C:\Users\jiahao\IdeaProjects\testtt\src
17:09:46.576: git -c core.quotepath=false checkout 69084f344b79a48da92855d3fb633a28a672a302
Previous HEAD position was 22d1c79... first commit
HEAD is now at 69084f3... second commit
17:18:26.999: cd C:\Users\jiahao\IdeaProjects\testtt\src
17:18:26.999: git -c core.quotepath=false commit --only -F C:\Users\jiahao\AppData\Local\Temp\git-commit-msg-0.txt -- C.java
[detached HEAD 783fbf2] third commit
1 file changed, 1 insertion(+)
git init
开始的所有步骤),以便复现这个问题,那将非常有帮助。 - Jon Skeetgit status
的结果。 - Jon Skeetgit reflog
相关的行吗? - xeor