Mercurial: get a new copy

I have a local repository and want to get the latest changes from a remote repository. I know that I can clone, but clone only works in new directories. I know that I can delete the local repository and then clone, but I want to know how to do this Mercurial, if any.

EDIT: hg pull -u does not work if there are conflicts. I do not want to resolve conflicts. I just want to get a new copy of the remote repo regardless of local changes.

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

The long answer: if you want to get the latest data from a remote computer and ignore your local changes and commit, you will have to clone a new local repository or delete a local repository and clone another one. This is because if you have conflicting changes, hg will force you to manually resolve them.

Which is good, but I just wanted to know if this could be done without deleting the local repo.

+7
source share
5 answers

It looks like you are looking for an hg strip that is not part of the Mercurial core. It is available through MqExtension. You can enable it by adding the following to your .hgrc or Mercurial.ini file ( https://www.mercurial-scm.org/wiki/MqExtension )

 [extensions] mq = 

Then you can:

 hg strip rev 

This will delete your change sets until you should not have merge conflicts. However, this will affect the history of the branches. But then again, it’s not so bad if you save any good future changes in them, you will have an ancestor that you decided to destroy.

If you just tried something, you better do it in a separate branch, which is easy to close and leave later.

If you really want to keep a bad set of changes, you can pass the configuration parameter to a merge command like this

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

This is described in Mercurial tips and tricks .

+2
source

I think you are just looking for this:

 hg pull hg up --clean 

This will lead to the latest patch set from the remote repo and then update the local repository with a clean copy, regardless of whether you made any changes to the files. No merge required.

The only caveat is that if you added files to your local repository and they were not committed, they will be lost (left in place, but not in the repository) after the update. If you execute hg stat , you will see that they are indicated by question marks. If the added files were transferred to your local repository, Mercurial will correctly 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 version 4 earlier) with the modified 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 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 

Changes to sample.txt were destroyed, addedtolocal.txt was deleted and addedtoremote.txt was added.

+4
source

Just β€œpull” the changes from the remote repo. Think of "pull" and "push" modifying transactions between repositories.

After that you need to β€œupdate” the sources.

+1
source

You can change your modifications while minimizing the need for mergers. Just call hg pull --rebase

In your ~/.hgrc you should have a rebase extension:

 [extensions] rebase = 
0
source

Since this is such a common action, there is an extension that executes hg pull -u , hg merge and hg commit in one command:

hg fetch

From hg book :

Enabling sampling expansion is very simple. Edit the .hgrc file in your home directory and either go to extensions or create extensions. Then add a line that just reads "fetch =".

 [extensions] fetch = 
-one
source

All Articles