使用git v1.7.1我试图同时对--preserve-merges
和--onto
功能进行重新绑定。最终结果似乎没有合并提交,因此看起来是线性的。我宁愿保留合并提交,原因与人们经常使用--preserve-merges
(更容易看到逻辑上是一个单独功能并在其自己的分支中开发的提交组)相同。git rebase“--preserve-merges --onto”不保留合并
我的主分支(目标为底垫)很无聊:
A-B-C
的特性分支我想从拿有已被合并到其子特性分支。像:
X - Y
/ \
V-W ------ Z
其中Z是一个合并提交是特性分支的负责人,从拿地,X和Y分别在子特性分支。
我使用:git rebase --preserve-merges --onto C V Z
我想直到结束:
X - Y
/ \
A-B-C-W ------ Z
但不是我越来越:
A-B-C-W-X-Y
,由于Z是一个受冲突自由合并,代码的最终状态是正确的,但历史并不像我想的那样富有表现力。
有没有办法得到我想要的东西?
编辑地址@Bombe: 我写了一个bash脚本来构造我的例子。在我的系统上(使用git 1.7.1的RHEL 6.2),这证明了我的问题。
#! /bin/bash
# start a new empty repo
git init
# make some commits on the master branch
git checkout master
touch A.txt; git add A.txt; git commit -m "add A.txt"; git tag Atag
touch B.txt; git add B.txt; git commit -m "add B.txt"; git tag Btag
touch C.txt; git add C.txt; git commit -m "add C.txt"; git tag Ctag
# now build the feature branch
# start at Btag (more or less arbitrary; point is it's before C)
git checkout Btag
git checkout -b feature
touch V.txt; git add V.txt; git commit -m "add V.txt"; git tag Vtag
touch W.txt; git add W.txt; git commit -m "add W.txt"; git tag Wtag
# now a subfeature
git checkout -b subfeature
touch X.txt; git add X.txt; git commit -m "add X.txt"; git tag Xtag
touch Y.txt; git add Y.txt; git commit -m "add Y.txt"; git tag Ytag
# merge the subfeature into the feature
# preserves branch history with --no-ff
git checkout feature
git merge --no-ff subfeature
# the merge commit is our Z
git tag Ztag
# one more commit so that merge isn't the tip (for better illustration of Z missing later)
touch postZ.txt; git add postZ.txt; git commit -m "add postZ.txt"; git tag postZtag
# now do the rebase
git rebase --preserve-merges --onto Ctag Vtag
# optionally move the master branch forward to the top of feature branch
git checkout master
git merge feature
底垫之前,我:
X-Y
/ \
V-W-----Z-postZ
/
A-B-C
底垫后,我得到:
X-Y
/ \
V-W-----Z-postZ
/
A-B-C-W'-X'-Y'-postZ'
注意缺少的Z和postZ” 'Y' 之间。
我编辑了原始帖子,提供重现我的问题的步骤。我相信你是对的,但我不明白我做错了什么。 – RaveTheTadpole 2012-03-01 23:03:50
我确实有一个大于1.7.5.2的版本。 :) – Bombe 2012-03-02 06:11:38