2

When I used gitk to check my branches, I found the following:

Git connected branches

I created pretty_url, switched to it, worked on stuff, committed, then switched to master branch (which was clean), then ran git merge pretty_url, and checked with gitk, and found this.

I'm sure this is not proper and probably the master wasn't clean. How can I fix this?

4

2 回答 2

6

这正是您对合并的期望。如果你想变基和快进,你可以这样做,并有一条直线。

例子:

在合并之前,您遇到过这种情况:

图片前

也就是历史masterbranch分歧。他们h作为一个共同的祖先共享。合并时(通过git merge branchwhile 在 `master 上),您最终会与两个父母一起提交以统一该历史记录:

合并图片

如果这不是您想要的,您可以撤消它并通过执行以下操作来获得您想要的:

git reset --hard HEAD@{1}  # or whatever commit matches 'j' to undo the merge
git checkout branch
git rebase master          # incorporate 'i' and 'j' commits into 'branch'
git checkout master
git merge branch           # this merge will be a fast-forward now

这将为您提供您似乎正在寻找的重新定位的线性历史:

快进图片

于 2013-08-21T16:37:10.687 回答
4

红线不表示不干净的分支;它只是意味着之前的提交masterpretty_url's head 更早。这里无需担心。此外,git merge不适用于不洁的树木。

于 2013-08-21T16:37:36.350 回答