Search code examples
netbeansmercurialmeld

How to properly push to a repository with a newer revision number?


Please help.

I'm always having a difficulty with pushing my changes to an existing remote repository where the revision number is newer. i.e. someone has pushed to that repository after I last pull.

I'm using ubuntu 14.04, and netbeans and mercurial and meld and my project is a php application using laravel framework.

my current solution is,

  1. to backup my local repository;
  2. then, in my first local repository, force update to the tip tag;
  3. fetch the latest in the remote repository using the first local repository;
  4. pull the latest in the remote repository (i don't know the difference between fetch and pull, if someone could shed some light, I would definitely be grateful);
  5. open meld; compare the two repository directories (the first local repository and the backup); remember what file(s) differ, then;
  6. in netbeans, apply alt+shift+f (Format) in each of the files that differ, in both directories, so that I could remove the unnecessary whitespaces and I could easily see the changes (when I compare the two directories again in meld) with proper indentation and clearer linebreaks;
  7. then, open meld, compare the two repository directories again, and this time, i could now easily understand the changes performed;
  8. apply the necessary changes to each repository until they are equal to each other (you have to be very careful in this step since it is already your backup that is being modified);
  9. commit the changes of the first local repository. which has the tip equal to the latest revision in the remote repository;
  10. then, push the committed changes.

I don't want to stay using this solution since it requires also that you have a second backup repository (in other words, storage capacity problems). Please help me find another solution.

If I do everything different, like, first, pulling the latest changes (by my colleagues) from the remote repository: I am getting an error:

abort: outstanding uncommitted changes

If I push first: the error is:

abort: push creates new remote heads on branch 'default'!
(did you forget to merge? use push -f to force)

then sometimes, if I pull using terminal, it requires me to merge. and it is very difficult to merge in terminal when you have no control which files are you going to merge first (the terminal opens the meld comparison tool for every changed files alphabetically),

and sometimes you have to apply "Format" first to each files to easily understand the objective of the changes performed.

but if you quit the merge, it would assume that you have successfully merged the files (or not? CMIIW.)


Solution

  • In short, Mercurial is already giving you the hint. You can pull in remote changes anytime. But you can't merge them with your changes, if you have uncommitted changes in your working directory.

    So just commit those (or shelve them, if you're not done yet), do a merge, resolve any conflicts, and commit the merge. Then you can push everything to the remote server.