Dowemo
0 0 0 0


Question:

(I am a relative newcomer to TortoiseHg, so bear with me :-) I use TortoiseHg on two machines to talk to my remote source repository. I made changes on one machine, committed them, and attempted to push them to the remote repository BUT I forgot to first do a pull to get the latest code first. The push gave me a few lines of output, suggesting I may have forgotten to pull first (true!) and mentioned something like "abort: push creates new remote branches...".

So I did a pull, which added several nodes to the head of my graph in the repository explorer. The problem is that the push I tried to do is now showing as a branch in the repository explorer. Looking from the server side (codeplex), it shows no sign of my attempted push, indicating this accidental branch is still local on my machine.

How could I remove this accidental branch? I tried selecting that node in the graph then doing "revert" but it did not seem to do anything. I am wondering if it would be simplest to just discard my directory tree on my local machine and do a completely new, clean pull from the server...?


Best Answer:


This is how to do it with the command-line tool. I guess it can be easily mapped to TortoiseHg (although I'm not sure, since I never use it...) Anyway, since it should be done just once in a while, I think there is no problem on using the terminal here.

An example setup

Suppose your remote repository is something like this:

@  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

Locally, you did not have commit 4, so you committed something directly over commit 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

So you try to push it, and get this message:

$ 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)

As requested, you pull it:

$ 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)

You have it now...

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

... but you would rather not merge as requested. You want to have this instead:

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

And then you want to push it to the remote repo.

How do you get that?

Solving it

To get that, you cannot have pushed the "commit 4 made locally". Also, there is no way to put it after the new remote commits. Said that, we can get what we asked.

Said that, you just need to rebase your local commit onto the new remote commit:

$ hg rebase --source 3 --dest 4

If you are lucky, that will be enough.

Handling conflicts

If you are unlucky, you may have some conflicts:

$ 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)

Then, just resolve the conflicts (by manually editing them):

$ hg st
M test.txt
$ nano test.txt # Edit and save

...mark the file as resolved...

$ hg resolve --mark
(no more unresolved files)
continue: hg rebase --continue

...and proceed with the 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

Here is your new history:

@  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

Now, push it:

$ 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

Those days, it is not as complex as it used to be, right? :)




Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs