0


git reset回退版本【Git异常】You are in ‘detached HEAD‘ state

一、背景

  • git clone项目后,在main分支回退版本,出现报错
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 switching back to a branch.
If you want to create a new branch to retain commits you create, you may
doso(now or later) by using -c with the switch command. Example:

detached HEAD称为分支游离状态

原因

1、从远程库clone下来一个远程的repository;
2、clone下来之后,git自动在本地建立了一个本地分支master,并自动与远程库master关联;
3、现在在操作checkout其他分支名(dev_v1);因为本地的工作区目前是刚刚clone的master分支的代码并且与远程关联,但是本机上没有本地分支与远程分支dev_v1关联,所以checkout一下就会出现detached head的状态(直接指向了commit id,因为git是离线版本控制,因为此checkout是远程的不是本地的,所以git只能给你一个commit id让你进行操作)

解决办法

切换为远程数据库已存在分支,如main分支

git checkout main
标签: git github

本文转载自: https://blog.csdn.net/r_omantic_man/article/details/130373621
版权归原作者 君临天下101 所有, 如有侵权,请联系我们删除。

“git reset回退版本【Git异常】You are in ‘detached HEAD‘ state”的评论:

还没有评论