在 Git 中分离 HEAD 并在变基时混淆冲突

Detached HEAD in Git and confusing conflicts when rebasing

我有两个新的远程分支结帐,一个分支 (crm-mania) 已经有几个月了,我正试图将它重新定位到主要开发分支 (master)。所以我有以下内容:

vagrant@localhost /var/www/current (crm-mania)$git branch
* crm-mania
  master

然后我执行以下操作:

    vagrant@localhost /var/www/current (crm-mania)$git checkout master
    Switched to branch 'master'
    vagrant@localhost /var/www/current (master)$git pull
    Already up-to-date.

然后我尝试 rebase 并得到以下信息(在我删除的其他消息中):

    vagrant@localhost /var/www/current (master)$git rebase master crm-mania
First, rewinding head to replay your work on top of it...
Applying: CRM-174: Mania Site
Using index info to reconstruct a base tree...
M       app/AppKernel.php
M       app/config/config.yml
M       app/config/routing_crmpicco.yml
<stdin>:107: trailing whitespace.
<?php
<stdin>:108: trailing whitespace.
/**
<stdin>:109: trailing whitespace.
 * @author    CRMPicco <crmpicco@crmpicco.co.uk>
<stdin>:110: trailing whitespace.
 * @date      02/04/2015
<stdin>:111: trailing whitespace.
 * @copyright Copyright (c) CRMPicco.
warning: squelched 1022 whitespace errors
warning: 1027 lines add whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging app/config/routing_crmpicco.yml
Auto-merging app/config/config.yml
CONFLICT (content): Merge conflict in app/config/config.yml
Auto-merging app/AppKernel.php
Failed to merge in the changes.
Patch failed at 0001 CRM-174: Mania Site
The copy of the patch that failed is found in:
   /var/www/releases/20150708141200/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

我遇到的主要问题是 HEAD 现在已分离,例如

vagrant@localhost /var/www/current (HEAD)$git status
# HEAD detached at e90cb5c

我还发现,如果我忽略此消息并尝试解决我的冲突,那么 Git 会在只有我处理过的代码中识别 "conflicts",并且只驻留在我的 [=15] 中=] 功能分支。他们绝对不在 master 分支中。

The main issue I have is that the HEAD is now detached

这是预期的行为。 git rebase 的工作方式是直接检查目标 SHA,这会将您置于分离的 HEAD 中。这恰好是 ourstheirsgit rebase 场景中与正常情况相反的原因。

每当你在变基期间发生合并冲突时,你将始终处于分离的 HEAD 状态。如果您 edit 交互式变基中的任何提交,也会发生这种情况。

至于为什么您会看到意外的冲突,如果不查看两个分支的变更日志就无法说清楚。通常答案是 "somebody else modified the code and I didn't realize it".