**Scenario:**
当自己修改完代码,准备commit之前做了一次pull+update,做了些解决冲突工作,然后验证代码是否正常工作。
确认一切正常后,执行hg commit,然后执行hg push。但是网络出现问题,push失败。等到网络恢复正常后,发现自己的版本已经不是最新版了,
push继续失败。提示:
abort: push creates new remote head 8f1da767f592!
hint: you should pull and merge or use push -f to force
**Merge:**
按照提示所述,我们需要更新代码并做一次merge操作才可以正常提交自己的代码。
执行hg pull后,hg很人性的提示我们:
(run 'hg heads' to see heads, 'hg merge' to merge)
当我直接执行hg merge时,hg再次提示我:
abort: outstanding uncommitted changes (use 'hg status' to list changes)
看来哪里还是有问题,好吧,先来看看merge的帮助吧。
~~~
$ hg merge --help
hg merge [-P] [-f] [[-r] REV]
merge working directory with another revision
The current working directory is updated with all changes made in the
requested revision since the last common predecessor revision.
Files that changed between either parent are marked as changed for the
next commit and a commit must be performed before any further updates to
the repository are allowed. The next commit will have two parents.
"--tool" can be used to specify the merge tool used for file merges. It
overrides the HGMERGE environment variable and your configuration files.
See "hg help merge-tools" for options.
If no revision is specified, the working directory's parent is a head
revision, and the current branch contains exactly one other head, the
other head is merged with by default. Otherwise, an explicit revision with
which to merge with must be provided.
"hg resolve" must be used to resolve unresolved files.
To undo an uncommitted merge, use "hg update --clean ." which will check
out a clean copy of the original merge parent, losing all changes.
Returns 0 on success, 1 if there are unresolved files.
options:
-f --force force a merge with outstanding changes
-r --rev REV revision to merge
-P --preview review revisions to merge (no merge is performed)
-t --tool VALUE specify merge tool
use "hg -v help merge" to show more info
~~~
尝试一下hg update --clean,看起来不错。
~~~
$ hg update --clean
8 files updated, 0 files merged, 1 files removed, 0 files unresolved
~~~
再次执行merge。
~~~
$ hg merge
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)
~~~
看起来成功了,按照提示,再commit一下。此时我们的提交信息只要告知一下这是一次merge操作即可。
然后push,成功。结果是原来的commit还是那时的changeset,最新的commit就是你刚刚提交的,信息为merge的那一条。
至此merge成功!