在Git中,我可以这样做:
1. Start working on new feature:
$ git co -b newfeature-123 # (a local feature development branch)
do a few commits (M, N, O)
master A---B---C
\
newfeature-123 M---N---O
2. Pull new changes from upstream master:
$ git pull
(master updated with ff-commits)
master A---B---C---D---E---F
\
newfeature-123 M---N---O
3. Rebase off master so that my new feature
can be developed against the latest upstream changes:
(from newfeature-123)
$ git rebase master
master A---B---C---D---E---F
\
newfeature-123 M---N---O
我想知道如何在Mercurial中做同样的事情,我在网上搜索了一个答案,但我能找到的最好的答案是:git rebase - hg能做到这一点吗
该链接提供了两个例子:
1. 我承认这一点:(用我自己的例子取代了这个例子的修订)
hg up -C F
hg branch -f newfeature-123
hg transplant -a -b newfeature-123
不是很糟糕,除了它留下了预重基M-N-O作为未合并的头,并创建了3个新的提交M',N',O',代表它们从更新的主线分支。
基本上问题是这样的:
master A---B---C---D---E---F
\ \
newfeature-123 \ M'---N'---O'
\
newfeature-123 M---N---O
这并不好,因为它会留下应该丢弃的本地、不需要的提交。
来自同一链接的另一个选项是
hg qimport -r M:O
hg qpop -a
hg up F
hg branch newfeature-123
hg qpush -a
hg qdel -r qbase:qtip
这就得到了我们想要的图:
master A---B---C---D---E---F
\
newfeature-123 M---N---O
但是这些命令(总共6个!)似乎比
$ git rebase master
我想知道这是否是Hg中唯一等效的方法,或者是否有其他简单的方法,如Git。
VonC有你正在寻找的答案,Rebase扩展。但是,值得花一秒钟或两秒钟思考一下为什么在mercurial中默认情况下既不启用mq也不启用rebase:因为mercurial都是关于不可删除的更改集。当我以你描述的方式工作时,我几乎每天都在工作,下面是我采取的模式:
1. Start working on a new feature:
$ hg clone mainline-repo newfeature-123
do a few commits (M, N, O)
master A---B---C
\
newfeature-123 M---N---O
2. Pull new changes from upstream mainline:
$ hg pull
master A---B---C---D---E---F
\
newfeature-123 M---N---O
3. merge master into my clone so that my new feature
can be developed against the latest upstream changes:
(from newfeature-123)
$ hg merge F
master A---B---C---D---E---F
\ \
newfeature-123 M---N---O---P
and that's really all that's necessary. I end up with a newfeature-123 clone I can easily push back to the mainline when I'm happy with it. Most importantly, however, I never changed history. Someone can look at my csets and see what they were originally coded against and how I reacted to changes in the mainline throughout my work. Not everyone thinks that has value, but I'm a firm believer that it's the job of source control to show us not what we wished had happened, but what actually happened -- every deadend and every refactor should leave an indelible trace, and rebasing and other history editing techniques hide that.
我把我的临时演讲台收起来,你去帮我选冯克的答案。:)
我不认为上面的答案达到了OP的目标,也就是维护他的任务分支,只是基于父分支的后面一个点。
假设我从这个图开始(使用graphlog扩展名生成)。极客对graphlog的热爱)。
@ 9a4c0eb66429 Feature 3 commit 2 tip feature3
|
| o af630ccb4a80 default againagainagain
| |
o | 98bdde5d2185 Feature 3 branch commit 1 feature3
|/
o e9f850ac41da foo
如果我在feature3分支上,并且想要从againagainagain的提交中重基它,我知道我会运行hg rebase -d default。这有以下结果:
@ 89dada24591e Feature 3 commit 2 tip
|
o 77dcce88786d Feature 3 branch commit 1
|
o af630ccb4a80 default againagainagain
|
o e9f850ac41da foo
任务完成了?我不这么想。问题是,当feature3分支上的提交被一次又一次地重新基于时,feature3分支被删除了。我的提交已经移动到默认分支,这是我首先要避免的。
在Git中,结果看起来是这样的:
@ 9a4c0eb66429 Feature 3 commit 2 tip
|
o 98bdde5d2185 Feature 3 branch commit 1 **feature3**
|
o af630ccb4a80 default againagainagain
|
o e9f850ac41da foo
注意,feature3分支仍然存在,两次提交仍然在feature3分支上,默认情况下不可见。如果不保留任务分支,我看不出这在功能上与合并有什么不同。
更新:我发现hg rebase支持的——keepbranches标志,我很高兴地报告一切都ok -dokey。使用hg rebase -d default——keepbranches,我完全复制了我渴望的Git行为。换了几个化名之后,我就改换基地了。
VonC有你正在寻找的答案,Rebase扩展。但是,值得花一秒钟或两秒钟思考一下为什么在mercurial中默认情况下既不启用mq也不启用rebase:因为mercurial都是关于不可删除的更改集。当我以你描述的方式工作时,我几乎每天都在工作,下面是我采取的模式:
1. Start working on a new feature:
$ hg clone mainline-repo newfeature-123
do a few commits (M, N, O)
master A---B---C
\
newfeature-123 M---N---O
2. Pull new changes from upstream mainline:
$ hg pull
master A---B---C---D---E---F
\
newfeature-123 M---N---O
3. merge master into my clone so that my new feature
can be developed against the latest upstream changes:
(from newfeature-123)
$ hg merge F
master A---B---C---D---E---F
\ \
newfeature-123 M---N---O---P
and that's really all that's necessary. I end up with a newfeature-123 clone I can easily push back to the mainline when I'm happy with it. Most importantly, however, I never changed history. Someone can look at my csets and see what they were originally coded against and how I reacted to changes in the mainline throughout my work. Not everyone thinks that has value, but I'm a firm believer that it's the job of source control to show us not what we wished had happened, but what actually happened -- every deadend and every refactor should leave an indelible trace, and rebasing and other history editing techniques hide that.
我把我的临时演讲台收起来,你去帮我选冯克的答案。:)
您可能正在寻找Rebase扩展。(作为SummerOfCode 2008的一部分实现)
在这种情况下,“分离”本地更改,将存储库与主流存储库同步,然后将私有更改附加在新的远程更改之上是很有用的。这个操作称为rebase。
从:
to:
steprobe的评论如下:
在这种情况下,你没有拉入更改,并且在你的回购中有两个分支,你可以这样做(使用keepbranches):
hg up newfeature-123
hg rebase -d master --keepbranches
(——keepbranches:继承原来的分支名。)
Mojca提到:
我喜欢使用hg rebase——source {L1's-sha}——dest {R2's-sha},但我不知道我可以在末尾添加——keepbranches。
如下乔纳森·布莱克本所示:
hg rebase -d default --keepbranches