Niklas Rosencrantz
Niklas Rosencrantz

Reputation: 26655

Mercurial usage to merge multiple heads

I'm mercurial newbie and want to learn how to use my repository. Can you tell me how to merge my friend's work with mine? Thanks

$ hg update tip
abort: crosses branches (merge branches or use --clean to discard changes)

$ hg heads
changeset:   265:ac5d3c3a03ac
tag:         tip
user:        roberto.cr
date:        Thu Oct 06 07:32:15 2011 +0000
summary:     fixing "redirects" links

changeset:   261:6acd1aaef950
user:        niklasro
date:        Thu Oct 06 07:53:19 2011 +0000
summary:     auth backend + js

$ hg update
abort: crosses branches (merge branches or use --clean to discard changes)

Could I use hg resolve?

$ hg resolve
abort: no files or directories specified; use --all to remerge all file

$ hg glog | more
@  changeset:   266:2bf5b62720fc
|  tag:         tip
|  parent:      261:6acd1aaef950
|  user:        niklasro
|  date:        Thu Oct 06 12:48:20 2011 +0000
|  summary:     added
|
| o  changeset:   265:ac5d3c3a03ac
| |  user:        roberto.cr
| |  date:        Thu Oct 06 07:32:15 2011 +0000
| |  summary:     fixing "redirects" links
| |
| o  changeset:   264:2fd0bf24e90f
| |  user:        roberto.cr
| |  date:        Thu Oct 06 07:29:58 2011 +0000
| |  summary:     fixing "redirects" links
| |
| o  changeset:   263:29a373aae81e
| |  user:        roberto.cr
| |  date:        Thu Oct 06 07:25:05 2011 +0000
| |  summary:     fixing "redirects" links
| |
| o  changeset:   262:d75cd4d3e77a
| |  parent:      260:dfb54b99f84d
| |  user:        roberto.cr
| |  date:        Thu Oct 06 07:24:55 2011 +0000
| |  summary:     fixing "redirects" links
| |
o |  changeset:   261:6acd1aaef950
|/   user:        niklasro
|    date:        Thu Oct 06 07:53:19 2011 +0000
|    summary:     auth backend + js
|
o  changeset:   260:dfb54b99f84d
|  user:        niklasro
|  date:        Wed Oct 05 05:34:37 2011 +0000
|  summary:     FB buggfix example.html
|
o  changeset:   259:92fb6b1bc492
|  user:        niklasro
|  date:        Thu Sep 29 16:42:33 2011 +0000
|  summary:     changes

The solution was hg revert -a and it looks like a success now

$ hg glog | more
@    changeset:   267:3b2bb6de33eb
|\   tag:         tip
| |  parent:      266:2bf5b62720fc
| |  parent:      265:ac5d3c3a03ac
| |  user:        niklasro
| |  date:        Thu Oct 06 16:06:21 2011 +0000
| |  summary:     merge
| |
| o  changeset:   266:2bf5b62720fc
| |  parent:      261:6acd1aaef950
| |  user:        niklasro
| |  date:        Thu Oct 06 12:48:20 2011 +0000
| |  summary:     added
| |
o |  changeset:   265:ac5d3c3a03ac
| |  user:        roberto.cr
| |  date:        Thu Oct 06 07:32:15 2011 +0000
| |  summary:     fixing "redirects" links
| |
o |  changeset:   264:2fd0bf24e90f
| |  user:        roberto.cr
| |  date:        Thu Oct 06 07:29:58 2011 +0000
| |  summary:     fixing "redirects" links
| |
o |  changeset:   263:29a373aae81e
| |  user:        roberto.cr
| |  date:        Thu Oct 06 07:25:05 2011 +0000
| |  summary:     fixing "redirects" links
| |
o |  changeset:   262:d75cd4d3e77a
| |  parent:      260:dfb54b99f84d
| |  user:        roberto.cr
| |  date:        Thu Oct 06 07:24:55 2011 +0000
| |  summary:     fixing "redirects" links
| |
| o  changeset:   261:6acd1aaef950
|/   user:        niklasro
|    date:        Thu Oct 06 07:53:19 2011 +0000
|    summary:     auth backend + js
|
o  changeset:   260:dfb54b99f84d
|  user:        niklasro
|  date:        Wed Oct 05 05:34:37 2011 +0000
|  summary:     FB buggfix example.html
|
o  changeset:   259:92fb6b1bc492
|  user:        niklasro
|  date:        Thu Sep 29 16:42:33 2011 +0000
|  summary:     changes

Upvotes: 14

Views: 43689

Answers (3)

Mark Booth
Mark Booth

Reputation: 7924

Since this was discussed in greater depth on the mercurial mailing list, it appears that the problem was that, as mpm suggested, the working directory wasn't clean.

To summarise that thread, before version 1.9m Mercurial would say nothing changed to an hg ci if files had just been deleted.

At 1.9 this was changed to say nothing changed (1 missing files, see 'hg status') to make it more explicit that while no filed had changed, there were still deletions and you need to tell hg what you want to do about them. Either use hg revert -a to discard the changes, or hg addremove plus hg commit to tell hg about the changes and commit them.

Also, as Matt Mackall says:

It might help to ask status to show only deleted files:

$ hg st -d
! setup.py

Upvotes: 4

mpm
mpm

Reputation: 1935

The basic problem here is that your working directory is not clean. Mercurial prevents people from accidentally jumping between branches with uncommitted changes as this is generally a bad idea.

Let's start with that first command:

$ hg update tip
abort: crosses branches (merge branches or use --clean to discard changes)

This is telling you two important things:

  • you're trying to cross branches
  • you have uncommitted changes

And that you have two options:

  • merge
  • use hg update --clean to lose your changes

So what are your changes? The first step is to run 'hg status'. As you say 'hg status outputs many files prepended by 1 or ?'. Well those '1s' are actually '!' indicating deleted/missing files (get a better font!). You should doublecheck against summary, which will give you output like this:

parent: 15200:fa6f93befffa 
 patch: use more precise pattern for diff header color styling (issue3034)
branch: default
commit: 1 deleted, 1 unknown (clean)   <- your changes
update: (current)

If you try to merge at this point, you'll get a message like:

$ hg merge stable
abort: outstanding uncommitted changes (use 'hg status' to list changes)

If you have changes other than missing files, you'll want to consider committing them.

If these missing files are your only changes, it's probably ok to discard them:

hg revert -a

After you've done that, you're in a state where Mercurial will let you update or merge without complaining.

Finally, you say "hg status output many files from other projects since it starts at .. The file I added is the only file that should get added.". This is a basic misunderstanding of how Mercurial works. Unlike CVS or SVN, there is only one project as far as Mercurial is concerned and actions (commit/update/merge/status) work on the entire project tree at once. Subdirectories are not independent projects with separate histories.

Upvotes: 22

Andreas
Andreas

Reputation: 2301

What about merging these two heads?

hg merge

Upvotes: 17

Related Questions