Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial: get fresh copy

Tags:

mercurial

I have a local repository and I want to get the latest changes from a remote repository. I know i can clone but clone only works on new directories. I know i can delete the local repository and then clone but i want to know how do it the Mercurial way if there is one.

EDIT: hg pull -u doesn't work if there are conflicts. I don't want to resolve conflicts I just want to get a fresh copy of the remote repo regardless of local changes.

ANSWER: Short answer: Maybe it can be done (see answer below) but re-clone is easier.

Long answer: if you want to get the latest from a remote and disregard your local changes and commits then you'll have to clone to a new local repository or remove the local repository and clone another one. This is because if you have conflicting changes then hg will force you to resolve them manually.

Which is OK but I just wanted to know if it can be done without removing my local repo.

like image 232
duraid Avatar asked Mar 23 '11 14:03

duraid


2 Answers

I think you're just looking for this:

hg pull
hg up --clean

That will pull latest set of revisions from the remote repoistory and then update your local repository with a clean copy, regardless of whether or not you have made any changes to the files. No merging necessary.

The only caveat is, if you have added files to your local repository, and they have not been committed, they will be orphaned (left in place, but not in the repository) after the update. If you do an hg stat you should see them denoted with question marks. If the added files have been committed to your local repository, Mercurial will properly clean up after them.

Here's the remote repository (remote rev 6):

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         3/24/2011   2:16 PM            .hg
-a---         3/24/2011   2:16 PM         83 addedtoremote.txt
-a---         3/24/2011   1:56 PM        726 sample.txt    

Here's the local repository (cloned from remote rev 4 earlier) with changed and added files (local rev 5):

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         3/24/2011   2:03 PM            .hg
-a---         3/24/2011   2:05 PM          9 sample.txt
-a---         3/24/2011   2:05 PM         58 addedtolocal.txt

Here's the local repository after doing a pull and clean update (local rev 6):

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         3/24/2011   2:17 PM            .hg
-a---         3/24/2011   2:17 PM         83 addedtoremote.txt
-a---         3/24/2011   2:15 PM        726 sample.txt    

The changes to sample.txt have been wiped out, addedtolocal.txt has been deleted and addedtoremote.txt has been added.

like image 58
Andy S Avatar answered Sep 23 '22 01:09

Andy S


Looks like you are looking for hg strip, which isn't part of the Mercurial core. It's available through the MqExtension. You can enable it by adding the following in your .hgrc or Mercurial.ini file (https://www.mercurial-scm.org/wiki/MqExtension)

[extensions]
mq =

Then you will be able to:

hg strip rev

This will remove your changesets to the point where you shouldn't have any merge conflicts. This will impact the branch history though. But then again, that's not so bad, if you keep them any good future changeset will have an ancestor that you decided to trash.

If you are just trying something out, you're better of doing it in a separate branch which is easy to close and abandon later.

If you really are looking to keep the bad changeset you can pass in configuration option to the merge command like this

hg --config ui.merge=internal:other merge 

This is documented in Mercurial tips and tricks.

like image 43
jfrobishow Avatar answered Sep 23 '22 01:09

jfrobishow