When using Mercurial HG, how to just get the latest code?
Asked Answered
K

7

22

I am new to Mercurial HG. My friends created a repo and I am going to use it. I installed TortoiseHG and trying to get the latest code. I found that when using Clone operation, it will pull all code to my local, including the histories (Am I right?). This is not needed for me. I just wanna get the latest code. Is there an operation for this?

Kate answered 17/11, 2010 at 14:9 Comment(1)
Thanks all your guys! Although I still have to clone the whole repo, I do learn more about Mercurial HG from every answer!Kate
M
19

In short, no.

In a bit longer: Mercurial doesn't yet support “shallow” clones where you only get part of the history. So each time you clone you pull in the entire repository with all changesets.

Additionally, unlike Subversion, there is no way to make a “narrow” clone where you only checkout a portion of a repository. For example, if a repository has directories foo/ and bar/, there is no way to get only the bar/ directory. In other words, Mercurial always operates on project-wide snapshots.

Maitund answered 17/11, 2010 at 14:16 Comment(4)
It seems history is an important thing for Mercurial. And it will always include the whole history.Kate
I changed the terminology in the answer to what we normally use in Mercurial: we talk about "shallow" clones when you only get part of the history and "narrow" clones when you only get part of the file tree.Snowcap
People have made prototypes for shallow clones, but they are not yet part of the main distribution.Snowcap
Git wins! This might just be reason enough for me to start migrating.Pfeiffer
E
6

The easiest way to achieve what you want:

hg archive [destination folder]
Ectopia answered 24/3, 2013 at 19:54 Comment(0)
D
4

Once you cloned a repository, to get the code of the "tip" (the last version of the current branch - the default one if not precised) you just need to update.

You have an update action in TortoiseHG. Once done, you can look at the files in the folder.

If you wanted another state of the repository (an old version, or an old tagged state) then it's still the update command, with other parametters (see the docs or the TortoiseHG interface).

Dorey answered 17/11, 2010 at 14:15 Comment(0)
F
3

If you only want the latest code, and you don't intend to do anything related to the repository with it, like commit, or diff to older versions, or whatever, then you it depends on where you got the code from and how.

If he is using one of the hosting services, like bitbucket, there's usually a download link which gives you just the source code.

For instance, if you go here, there's a "Get source" link up and to the right which gives you a few choices in the file format (zip or whatnot.)

If you got the files somewhere else, you need to explore the interface you got them from. Try just pasting the link you cloned from into your browser and see what you get.

Flattop answered 17/11, 2010 at 14:15 Comment(1)
I do need to take operations such as checkin and adding files. Still I am treating Mercurial as SVN...Kate
K
3

Sure. Clone the repository, then delete the .hg subdirectory.

Koblick answered 17/11, 2010 at 22:57 Comment(1)
The problem is, it still cast lots of time to clone the whole repo. Seems it have to....Kate
L
2

I might be a bit late but actually it is possible to forget some history with Mercurial. You just need to enable convert extension from Your mercurial.ini file or .hgrc file.

[extensions]
hgext.convert= 

Now you are able to use convert extension to "clone" only changesets starting from the revision specified.

hg convert --config convert.hg.startrev=[wheretostart] path_to_full_history_repo path_to_new_repo

Just note that this is not the same operation with hg clone. That's why the source repository must be a local repository. For example if we have a repository in folder MyProject and we want to forget all the changes done before revision 100. We can use the following command:

hg convert --config convert.hg.startrev=[100] MyProject MyShrinkedProject

If You are going to use this shrunken repository on a "central server" remember to take care of that everybody clones it before they continue working. Repositories are not compatible with each other anymore.

Lampas answered 30/11, 2015 at 9:14 Comment(1)
This answer assumes it is OK to get a full clone once, and from then on use only a partial clone. It is a good solution if you do need some of the history, but only going back to a certain revision. If you want to start fresh with no history at all: 1. Start with a full clone. 2. Run hg manifest and save the result to a file. 3. Delete the .hg folder. 4. Run hg init. 5. Run hg add on the saved list of files.Redintegration
H
1

Mercurial now supports shallow clone using remotefilelog extension. Extension is bundled with mercurial probably since version 4.9. Older versions need to download the extension e.g. from github.

You have to enable it on the server e.g:

[extensions]
remotefilelog =

[remotefilelog]
server = True
serverexpiration = 14

and on client

[extensions]
remotefilelog =

[remotefilelog]
cachepath = /some/path
cachelimit = 5 GB

Than you can do shallow clone with much smaller footprint a and faster clone speed:

hg clone --shallow ssh://user@server/repo

Hydrosol answered 22/9, 2020 at 19:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.