这是使用命令行工具执行此操作的方法。我想它可以很容易地映射到 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
那些日子,它不像以前那么复杂了,对吧?:)