zoukankan      html  css  js  c++  java
  • git游离状态解决方案 HEAD is now at 029bab7f xx

    git游离状态产生的原因是:使用git命令checkout版本时,不小心checkout到了远程分支,但此分支本地并没有,因此此时会处于 'detached HEAD' 状态,

    即本地HEAD找不到本地分支会指向远程分支的最后一次提交.

    问题现象:

    一.会提示

    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: git switch -c Or undo this operation with: git switch- Turn off this advice by setting config variable advice.detachedHead

    to false HEAD is now at da589bf6 

    二.此时运行git branch -a发现有(HEAD detached at xxx)这种奇怪的本地版本 这样的提示.

    此时不要慌,百度了很多,都是这种解决方法 https://www.cnblogs.com/kibana/p/8917501.html 但明显是天下文章一大抄,这种其实没有说全,明显的硬伤是在第二步时根本无法切到主分支,

    因为此问题的核心是本地没有远程的主分支.

    此时建议:

    1.git fetch 获取所有分支,先获取所有最新远程分支
    
    2.git branch -a 所有分支,查看所有分支
    
    3.git checkout -b 4.0 origin/mrh/4.0.0 拉取远程到本地
    
    4.git branch tmp da589bf6 创建一个临时分支合并上面最后一次提交id
    
    5.git checkout 4.0 再切到本地4.0,准备合并临时分支
    
    6.git merge tmp  合并临时分支
    
    此时会提示 Your branch is ahead of 'origin/mrh/4.0.0' by 2 commits. (use "git push" to publish your local commits) 提示比远程分支比2个版本,
    说明即将成功了,合并了最新的改动(这时因为我本地同时有最新的改动,瞎操作导致的,一般游离应该不会有) 重新push到origin/mrh/4.0.0 远程分支后再次使用git branch -a查看,
    
    发现没有了 (HEAD detached at xxx) 这种版本,说明成功解决了.
    7.此时可以删除tmp分支了,git branch -D tmp 删除分支.
  • 相关阅读:
    Python3+Flask安装使用教程
    Linux getopt/getopts解析命令行参数教程
    Python3+unittest使用教程
    Python3+slowloris安装使用教程
    pytest pluggy.manager.PluginValidationError: unknown hook 'pytest_namespace'报错处理办法
    Python3+Django get/post请求实现教程
    Jenkins安装使用教程
    安全基线自动化扫描、生成报告、加固的实现(以Tomcat为例)
    Scratch安装使用教程
    从安装Mac OS X虚拟机到第一个IOS程序
  • 原文地址:https://www.cnblogs.com/lpcyj/p/14139315.html
Copyright © 2011-2022 走看看