这是如何使用命令行工具完成的。我想它可以很容易地映射到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
然后你想把它推到远程仓库。
你怎么做到的?
解决它
为了实现这一点,你不能推送本地提交的#34;#34;。此外,在新的远程提交之后,无法将其设置为。说,我们可以得到我们所要求的。
说,你只需要将你的本地提交重新绑定到新的远程提交:
$ 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
...继续使用rebase:
$ 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
那些日子,它并不像以前那么复杂,对吧? :)