开发者

Rebasing a Detached HEAD against a master branch

开发者 https://www.devze.com 2023-03-09 22:33 出处:网络
I use gerrit at my job, and it requires use of rebase instead of merge commits. Today I checked out a previous commit using its hash value, and when I ran the git branch command, I was informed I was

I use gerrit at my job, and it requires use of rebase instead of merge commits. Today I checked out a previous commit using its hash value, and when I ran the git branch command, I was informed I was on "no branch". I assume this is a detached HEAD? In any case, I rebased against my my master branch, and the console printed

Using index info to reconst开发者_运维知识库ruct a base tree...
Falling back to patching base and 3-way merge...

Where does the '3-way merge' in this situation come from? And was the HEAD still detached after the rebase (considering the 'base-tree' statement)? Thank you.


Yes 'no branch' means detached HEAD

The base revision comes from doing

git merge-base <yourrevision> master

It will look at the last common ancestor (or merge point, which is considered a common ancestor even if there were manual conflicts) to establish a base version.

After a rebase, you are normally always on a new detached HEAD, IIRC. Now there are numerous ways in which to call rebase (including --onto --root) and they may behave slightly differently. So if you care to post the rebase command used, I may verify my thinking and perhaps add some comments.


As illustrated here, this error message is usually the sign of a conflict:

The conflict does not go away by itself, but in this case we fix the conflict and continue, and the original patch "Added another message" will be itself changed:

$ vi main.c
$ git add main.c
$ git rebase --continue

The key is to continue the rebase after fixing the conflict.

0

精彩评论

暂无评论...
验证码 换一张
取 消