Question

I have a file, version.txt and other files. I changed the other files, but didn't touch version.txt.

So, I've tried to push a commit, and saw a Remote heads error. (There is a changeset which modifies versions.txt file)

I did a hg pull, then hg update.

The error is: abort: crosses branches (merge branches or use --clean to discard changes)

Then I tried hg merge: abort: outstanding uncommitted changes (use 'hg status' to list changes)

But I don't undertand, why if the versions.txt isn't modified by me, why can't it just merge.

This is something I will be doing a lot, which is, develop and merge, to keep inline with the main dev repo. How can I fix this thing?

HG Status:

M printbox/web/printbox/controllers/ct_adm_colas.php
M printbox/web/printbox/controllers/ct_adm_jobs.php
M printbox/web/printbox/controllers/ct_form_configurar_cola.php
M printbox/web/printbox/core/MY_Controller.php
M printbox/web/printbox/css/estilos.css
M printbox/web/printbox/js/js_tablas_colas-jobs_ajax.js
M printbox/web/printbox/models/md_cola.php
M printbox/web/printbox/models/md_job.php
M printbox/web/printbox/views/vw_tabla_colas.php
M printbox/web/printbox/views/vw_tabla_jobs.php
A printbox/web/printbox/core/MY_Model.php
? .idea/.name
? .idea/encodings.xml
? .idea/misc.xml
? .idea/modules.xml
? .idea/printboxweb.iml
? .idea/scopes/scope_settings.xml
? .idea/vcs.xml
? .idea/workspace.xml

EIDT: Before and After following the suggested fix, the graph log looks like this:

o  changeset:   19:e21fa7b131b0
|  tag:         tip
|  parent:      17:54f59f253460
|  user:        JCV
|  date:        Tue Apr 22 12:33:36 2014 -0300
|  summary:     # Modificar nombre de producto para version
|
| @  changeset:   18:a03eaad764cd
|/   user:        Jorge S <js@fusiondev.com.ar>
|    date:        Wed Apr 23 16:28:01 2014 -0300
|    summary:     Eliminar método que no se utiliza.
|
o  changeset:   17:54f59f253460
|  user:        Jorge S <js@fusiondev.com.ar>
|  date:        Mon Apr 21 17:25:23 2014 -0300
|  summary:     Incluir SWHelper en Printbox.php
|


@    changeset:   21:1698791a9310
|\   tag:         tip
| |  parent:      20:3bfa1251da1b
| |  parent:      19:e21fa7b131b0
| |  user:        Jorge S <js@fusiondev.c
| |  date:        Thu Apr 24 13:59:25 2014 -0300
| |  summary:     Merge
| |
| o  changeset:   20:3bfa1251da1b
| |  parent:      18:a03eaad764cd
| |  user:        Jorge S <js@fusiondev.c
| |  date:        Thu Apr 24 13:57:23 2014 -0300
| |  summary:     Commit de archivos
| |
o |  changeset:   19:e21fa7b131b0
| |  parent:      17:54f59f253460
| |  user:        JCV
| |  date:        Tue Apr 22 12:33:36 2014 -0300
| |  summary:     # Modificar nombre de producto 
| |
| o  changeset:   18:a03eaad764cd
|/   user:        Jorge S <js@fusiondev.c
|    date:        Wed Apr 23 16:28:01 2014 -0300
|    summary:     Eliminar método que no se utili
|
o  changeset:   17:54f59f253460
|  user:        Jorge S <js@fusiondev.com
|  date:        Mon Apr 21 17:25:23 2014 -0300
|  summary:     Incluir SWHelper en Printbox.php
Was it helpful?

Solution

Ok, forget about version.txt, it is not relevant here. You have 2 repos, one on your system, and the remote one.

When you tried to push the first time, you tried to send a changeset on the remote repo, and you got an error saying that you cannot push a second head, unless you issue a --force option. This is because someone else already beat you to it and pushed a changeset (modifying version.txt) on the same branch (what you call main line, is actually a branch too, and it is probably called default).

What you did next is good, you pulled the changes from the remote repo to solve the 2 heads problem. By doing so, you are the one ending up with 2 heads on the default. This is fine, it is easy to solve, we'll get to it soon.

Your current state must look like this

% hg log --graph
o  changeset:   14:3cfac6413110
|  tag:         tip
|  parent:      10:d573f47ecc2d
|  summary:     vb
|
| @  changeset:   13:d8edfdb0532e
|/   parent:      10:d573f47ecc2d
|    summary:     commit to subr2
|

Now it gets complicated when you do the hg update because mercurial notices that something is wrong with your repo. You will need to fix the 2 heads issue by doing a merge, just like mercurial's suggestion.

However, doing hg merge gives you a second error, this time because you have not committed all your changes in your repo. Now you have 2 choices. You see those files with the M in front of them when you tried the hg status command? If you indeed modified them, and you want to include them in the repo, do the following:

hg commit -m "Committing remaining files"
hg merge
hg commit -m "Merge"

This is to commit the left-over changes, merge the 2 heads, then commit the merge changeset. The reason why mercurial does not want to update with uncommitted changes is for security reasons. It does not want you to loose you current work. And this brings me to the second option. If, however, the changes in the modified files are not wanted, you can discard those changes. It is possible you attempted something else during the confusion, which updated some files and left you in an in-between state. If that is the case, you can quickly discard the changes and solve the problem by doing these commands instead (loosing your changes):

hg update --clean
hg merge
hg commit -m "Merge"

The update will simply clean out the repo, and a merge will be possible. Once the merge committed, then you can issue the final push.

hg push

If you're lucky and no one pushed anything else on the remote repo, the push should succeed. Otherwise, you can pull, merge, commit and push again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top