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
do so (now or later) by using -c with the switch command. Example:
detached HEAD称为分支游离状态
原因
1、从远程库pull down一个remote repo。
2、pull down之后, git会automatically create a local branch named master and link it to the remote master repository.
3、现在尝试 checkout 其他分支名(dev_v1);由于当前local working directory包含刚pull下来的master代码并与其保持连接,但本机没有对应的local支div与remote dev_v1支div相关联,因此Checkout会result in a detached head pointing to a commit ID.
4、因为这个Checkout operation是remote而非local进行的.
解决办法
切换为远程数据库已存在分支,如main分支
git checkout main
全部评论 (0)
还没有任何评论哟~
