git - 使用 git reset --hard "commit id",现在我的 HEAD 已分离
问题描述
我对 git 比较陌生。
问题:只想将我的远程主分支与合并分支合并。
我想将我的远程主分支与我正在处理的合并分支同步:合并分支在主分支后面有 80 个提交。由于某种原因,我遇到了一些冲突,自动合并失败。
然后我尝试切换到我的远程主分支(git checkout origin/main),它也失败了,建议我先解决冲突。我决定简单地回到之前的提交,为此我使用了:
git reset --hard *commit id*
然后我删除了我的合并分支,并继续从远程主分支(origin/main)创建一个新的合并分支。这就是问题的开始。我写的
git checkout origin/main
我收到了这个
Note: switching to 'origin/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:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at *commit id* *Description*
我尽我所能,阅读文章,阅读 stackoverflow 问题,甚至删除并克隆了我的本地存储库,但不知何故无法将 HEAD重新附加到远程分支,如果可以的话。
有什么我在这里想念的吗?我想要的只是使用 git checkout origin/main 它应该指向分支而不是特定的提交 ID。
任何和所有的帮助表示赞赏。自从过去 5 个小时以来,我一直在努力解决这个问题。
解决方案
然后我删除了我的合并分支,并继续从远程主分支 (origin/main) 创建一个新的合并分支
这实际上不是你所做的。git checkout origin/main
检查了引用的提交origin/main
,因此最终处于分离的头部状态。
你需要做的是git checkout -b merge origin/main
。这将有效地创建本地merge
分支origin/main
并检查它。
如果您当前处于分离头状态,您应该能够执行上述命令来解决您的问题。
推荐阅读
- r - 根据存储在另一个列表中的索引,在列表中存储的数据帧的 R 列中进行子集化
- android - Yalantis的uCrop库中的sourceUri和destinationUri是什么意思以及如何获取?
- ruby-on-rails - 在 Elastic Beanstalk 上更改节点和 NPM 版本
- javascript - 如何使用 Ajax 动态更新 JSON-LD 脚本?
- django - 将文件字段保存为无,但在数据库中反映空字符串
- mongodb - mongo db schema 关系或在集合中
- javascript - 事件出队后,Javascript 事件循环如何处理非阻塞函数调用的执行?
- c - 一起使用 '#' 和 '##' 预处理运算符
- algorithm - 级别和相同时的递归树
- azure - 无应用服务的 Azure Function 发布管道(用于消费计划)