“git checkout< commit id>”正在将分支改变为“不分支” [英] "git checkout <commit id>" is changing branch to "no branch"

查看:505
本文介绍了“git checkout< commit id>”正在将分支改变为“不分支”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在git的分支上工作。当我做的时候

  git checkout< commit id> 

(从 git log 获取的提交ID) ,它正在致力于该特定更改,但分支更改为<无分支>



这是否发生?你如何解决这个问题? 一个分离头状态,基本上只是表示当前工作副本已经检出,并没有分支指向它。



如果你还没有提交任何提交,你可以离开头部状态,只需在签出提交之前签出你所在的分支:

c $ c> git checkout< branch>

如果您在脱离头部状态时确实进行了提交,则可以简单地保存工作

 #在当前检出一个新的分支分离头状态:
git checkout -b newBranch

您可以阅读更多关于在官方Linux Kernel Git文档中分离头部状态, a>。


I am working on a branch in git. When I do

git checkout <commit id>

(commit id obtained from git log ), it is getting committed to that particular change but branch is changed to <No-branch>.

Why is this happening? How do you resolve this?

解决方案

If you checkout a commit sha directly, it puts you into a "detached head" state, which basically just means that the current sha that your working copy has checked out, doesn't have a branch pointing at it.

If you haven't made any commits yet, you can leave detached head state by simply checking out whichever branch you were on before checking out the commit sha:

git checkout <branch>

If you did make commits while you were in the detached head state, you can save your work by simply attaching a branch before or while you leave detached head state:

# Checkout a new branch at current detached head state:
git checkout -b newBranch

You can read more about detached head state at the official Linux Kernel Git docs for checkout.

这篇关于“git checkout&lt; commit id&gt;”正在将分支改变为“不分支”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆