75

Ok I've had a little google and can't find a solution as i've stumbled across the same message but different ways in which people have got it. I'm new to mecurial and want to make sure i'm doing this correctly.

So i'm getting the error message as above. I have a dev site and a live site and i'm trying to push the code to codebase.

However yesterday I accidentally did hg add which added all the media which i didn't want to do. I did revert after to remove all the media files from codebase, by then committing and push the changes. So today i've been making changes to the CSS file and a few templates. I've gone to commit my changes and push them but when i run hg push I get the error above.

I've run hg log and there are only 6 commits as it's a clean/new branch/project. Any help would be much appreciated and I apologize if i've not explained anything correctly!

Kamil Naja
  • 6,267
  • 6
  • 33
  • 47
JDavies
  • 2,730
  • 7
  • 34
  • 54

5 Answers5

74

This isn't an "error" message; it's a totally normal situation. That message is saying "hey, other people pushed new work to that repository while you were doing your work, you should probably integrate theirs into your so they don't have to integrate yours into theirs?"

So first do a:

hg pull

and then a:

hg merge

Incidentally the revert you did if you actually used the hg revert command didn't remove those files from history, so your history is probably pretty big.

Consider reading the first few chapters of the Mercurial book it covers these situations quite well.

Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
  • 1
    A legitimate situation is if you need to create a patch based on a very specific older version. You can then later merge that patch into your main dev branch. – AnthonyVO Nov 01 '18 at 20:14
  • @AnthonyVO And what's the solution in this situation? I have to patch an old release. hg push -f ? – The incredible Jan Nov 18 '22 at 09:36
  • 1
    @TheincredibleJan, 1. Get the release/version you NEED to patch, 2. Make and commit the changes (creating a new head if required), 3. Merge the changes back into the main branch. Repeat until you no longer need to maintain the older release. Your objective is to limit the scope of any patches. Very often, the users prefer to upgrade all the way to a new release instead of the patch I just created for them. – AnthonyVO Nov 18 '22 at 18:01
21

If you want to cancel your conflicting changes

hg outgoing

You should see lines containing your commited/conflicting changes which are not pushed. Search for the changeset revision. Here 64

searching for changes
changeset:   64:1830948c246e

Then

hg strip 64
Woody
  • 809
  • 8
  • 21
19

This worked for me.

hg push -f

For more command, try

hg help push
Matt
  • 74,352
  • 26
  • 153
  • 180
  • 13
    Adding the "force" flag isn't really a "solution" any more than "creates new remote head" is an error.. – Caius Jard Jun 28 '16 at 14:29
  • 7
    This is a _solution_, but only if you know what you are doing. For instance when you close a branch and want to restart the branch (without merge, overriding any changes of the closed branch, but with the same name), then `--force` is probably what you want. The key here is to _know what you are doing_, otherwise don't use `--force` (which should be your default). – Abel Feb 15 '17 at 10:46
  • This is NOT a solution?! I have to patch an old release and this message prevents a push. If this is not an error why it don't just do what I want without getting on my nerves? What should I do instead of this? – The incredible Jan Nov 18 '22 at 09:40
1

On TortoiseHg you can do this:

1 => Commit your files

2 => Go do your new branch, where you want to push your code

3 => On this branch, run Merge with develop

4 => Push your code whithout errors!

Kamil Naja
  • 6,267
  • 6
  • 33
  • 47
  • "Merge with develop"? What "develop"? Do you mean "default"? I can't merge. I have to leave any other old code untouched and only want do push my changes. – The incredible Jan Nov 18 '22 at 09:42
0

If you are using the Workbench to push the changes you can try the Detect outgoing changes first, See the attached Image

enter image description here

This will give you info on what is you are going to push. My issue was, i had an old draft pending to be pushed. I was able to continue with the push once i have done strip on the old draft.

Akbar Badhusha
  • 2,415
  • 18
  • 30
  • 1
    You can also simply filter the repository to `draft()` (show the revisions in 'draft' state). (This is not 100% reliable, if you have done something fancy like changing the revision state or pulled/pushed to a different repository, but under normal circumstances it will work.) – Mike Rosoft Oct 18 '19 at 13:26