以下是使用命令行工具的方法。我猜它可以很容易地映射到TortoiseHg(虽然我不确定,因为我从来没有使用过...)无论如何,由于应该只偶尔执行一次,我认为在这里使用终端没有问题。
一个设置示例
假设您的远程存储库类似于此:
@ changeset: 3:a4c18a1fba12
| tag: tip
| summary: commit 4
|
o changeset: 2:91c5dbfba15c
| summary: commit 3
|
o changeset: 1:4c77cb7952ea
| summary: commit 2
|
o changeset: 0:085dae46f27e
summary: commit 1
在本地,您没有提交4,因此您直接在提交3之上提交了一些内容:
@ changeset: 3:39526003350f
| tag: tip
| summary: commit 4 made locally
|
o changeset: 2:91c5dbfba15c
| summary: commit 3
|
o changeset: 1:4c77cb7952ea
| summary: commit 2
|
o changeset: 0:085dae46f27e
summary: commit 1
所以你尝试推送它,然后得到这个消息:
$ hg push
pushing to ssh://hg@bitbucket.org/brandizzi/mercurial-test-repo
searching for changes
remote has heads on branch 'default' that are not known locally: a4c18a1fba12
abort: push creates new remote head 39526003350f!
(pull and merge or see "hg help push" for details about pushing new heads)
根据您的要求,您可以拉取它:
$ hg pull
pulling from ssh://hg@bitbucket.org/brandizzi/mercurial-test-repo
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
(run 'hg heads' to see heads, 'hg merge' to merge)
现在你拥有了...
o changeset: 4:a4c18a1fba12
| summary: commit 4
|
| @ changeset: 3:39526003350f
|/ summary: commit 4 made locally
|
o changeset: 2:91c5dbfba15c
| summary: commit 3
|
o changeset: 1:4c77cb7952ea
| summary: commit 2
|
o changeset: 0:085dae46f27e
summary: commit 1
...但是你不想按照要求合并。相反,你想要这个:
o changeset: 4:a4c18a1fba12
| summary: commit 4 made locally
|
o changeset: 3:a4c18a1fba12
| summary: commit 4
|
o changeset: 2:91c5dbfba15c
| summary: commit 3
|
o changeset: 1:4c77cb7952ea
| summary: commit 2
|
o changeset: 0:085dae46f27e
summary: commit 1
然后你想将它推送到远程仓库。
你怎么做到的呢?
解决方法
要做到这一点,你不能已经推送了“本地提交4”。此外,也没有办法将其放在新的远程提交之后。既然如此,我们可以得到我们所要求的。
因此,你只需要将本地提交变基到新的远程提交上:
$ hg rebase --source 3 --dest 4
如果你很幸运,那就足够了。
处理冲突
如果你不幸的话,可能会遇到一些冲突:
$ hg rebase --source 3 --dest 4
rebasing 3:39526003350f "commit 4 made locally"
merging test.txt
warning: conflicts while merging test.txt! (edit, then use 'hg resolve --mark')
unresolved conflicts (see hg resolve, then hg rebase --continue)
然后,只需解决冲突(通过手动编辑它们):
$ hg st
M test.txt
$ nano test.txt # Edit and save
...标记文件为已解决...
$ hg resolve --mark
(no more unresolved files)
continue: hg rebase --continue
...然后继续进行变基:
$ hg rebase --continue
rebasing 3:39526003350f "commit 4 made locally"
saved backup bundle to /home/adam/software/mercurial-test-repo/.hg/strip-backup/39526003350f-64863882-backup.hg
这是您的新历史记录:
@ changeset: 4:ca31fe8a15f0
| summary: commit 4 made locally
|
o changeset: 3:a4c18a1fba12
| summary: commit 4
|
o changeset: 2:91c5dbfba15c
| summary: commit 3
|
o changeset: 1:4c77cb7952ea
| summary: commit 2
|
o changeset: 0:085dae46f27e
summary: commit 1
现在,推送它:
$ hg push
pushing to ssh://hg@bitbucket.org/brandizzi/mercurial-test-repo
searching for changes
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 1 changesets with 1 changes to 1 files
现在的日子,不像以前那么复杂了,对吧?:)