【Git异常】You are in ‘detached HEAD‘ state, which means that you‘re not on any branch Checkout a branch

简介: 【Git异常】You are in ‘detached HEAD‘ state, which means that you‘re not on any branch Checkout a branch

You are in 'detached HEAD' state, which means that you're not on any branch Checkout a branch to make update possible.

一、背景描述

使用 IDEA编译器 更新项目时,居然更新不成功,报错内容如下:

Can't Update:No Current Branch

You are in 'detached HEAD' state, which means that you're not on any branch Checkout a branch to make update possible.

图示:

二、报错原因

Git出现分支游离状态(detached head),detached head是一种HEAD指针指向了某一个具体的 commit id,而不是分支的情况。在这个状态下进行的commit不会对你的远程分支产生影响。

而出现游离状态的原因有以下几点:

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

三、解决办法

切换到你的工作分支即可,命令如下:git checkout XXXX(分支名)

完结!


相关文章
|
3月前
|
开发工具 git
git checkout (branchname
git checkout (branchname) 是 Git 中切换分支的一种命令。通过这个命令,你可以将当前工作目录切换到指定的分支上。branchname 参数是可选的,如果不指定,则默认切换到主分支(master 或 main)。
37 2
|
2月前
|
开发工具 git 开发者
|
3月前
|
开发工具 git
git branch (branchname)
git branch (branchname) 是 Git 中创建和管理分支的一种命令。通过这个命令,你可以根据指定的分支名创建一个新的分支,或者跳转到已经存在的分支上。branchname 参数是可选的,如果不指定,则默认创建或切换到主分支(master 或 main)。
59 8
|
3月前
|
网络安全 开发工具 git
git修改提交路径以及强制提交——异常:error: remote origin already exists.与异常:error: failed to push some refs to的解决
git修改提交路径以及强制提交——异常:error: remote origin already exists.与异常:error: failed to push some refs to的解决
20 0
|
9天前
|
开发工具 git
避免git产生Merge branch 'foo' into 'bar'提交
避免git产生Merge branch 'foo' into 'bar'提交
30 3
|
7月前
|
Shell 开发工具 git
【Git】解决Untracked Files Prevent Checkout的问题
【Git】解决Untracked Files Prevent Checkout的问题
336 0
|
8月前
|
Ubuntu Linux 开发工具
idea使用git提交代码报异常refusing to merge unrelated histories和unknown option `allow-unrelated-histories‘
idea使用git提交代码报异常refusing to merge unrelated histories和unknown option `allow-unrelated-histories‘
|
8月前
|
开发工具 git 开发者
解决fatal: not a git repository (or any of the parent directories): .git问题
解决fatal: not a git repository (or any of the parent directories): .git问题
1080 1
|
5月前
|
开发工具 git
解决:fatal: not a git repository (or any of the parent directories): .git的问题
解决:fatal: not a git repository (or any of the parent directories): .git的问题
|
7月前
|
运维 Shell 开发工具
【Git异常】Push master to origin/master was rejected by remote
【Git异常】Push master to origin/master was rejected by remote
104 0

相关实验场景

更多