开发者

git merge loses the branch reference

Overview:

$ git pull
... time passes ...
$ git checkout topic # remote topic
$ git checkout master
$开发者_Go百科 git merge topic
$ git push
    non-fast-forward updates were rejected
$ git pull
    merge by rebase
$ git push

The result is that the file changes are pushed but the reference back to the topic branch has been lost. (On github, this results in a pull request not closing.) It also makes the graph look odd in that topic branch is not shown to be merged into master.

The trigger for causing this to happen is a pull after the merge that requires a merge. That is, master was changed during the topic merge.

The setting for pull is to always use pull --rebase.

As a further side affect a tag placed on the merge point was kind of lost. The tag was never pushed (although it was requested).

We were able to fix the graph by re-merging the topic branch.

How can we avoid this in the future? What is it that causes this problem? It doesn't feel like we've done anything incorrectly.

Thanks!

ps The config is set to only pull/push the current branch.


The "fix" is to not use pull --rebase - rebasing is what is losing your history. The entire point of merging instead of rebasing is to keep the separate branch history around.

git pull is normally the equivalent of git fetch+git merge.

git pull --rebase is git fetch+git rebase.

The former preserves history links; the latter creates entirely new commits. (Is there a particular reason you have git pull set to always rebase?)

You can also do a git pull on master before you merge in topic to try to ensure that master is up to date (so that the merge won't result in a non-fast-forward history).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜