How to Pull from specific changeset - mercurial

Recently I am working on Mercurial Repository. But I don't know how to pull version control from specific change-set ID on Mercurial ? Could you please share me any solution ?

You need to use the -r option, to pull the changeset and all its ancestors:
hg pull -r <hash>
Alternatively, use the -b <branch> option to get a specific branch.

First pull the source:
hg pull
Then update to specific revision:
hg up -r <changeset number>

Related

Mercurial HG - How to clean repo from uncomm­itted files and stay in the current changeset?

I am using Mercurial ("HG"), I am trying to Clean the repo from uncomm­itted Changes using :
hg update --clean -R rpeo_path
It will Clean The repo and move to tip ( it will change the changeset )
How can i Clean the repo from uncomm­itted changes and stay in the current Changeset ?
Thanks in advance
The simplest is probably to use hg revert --all.
With no revision specified, revert the specified files or directories
to the contents they had in the parent of the working directory. This
restores the contents of files to an unmodified state...
The --all option will
revert all changes when no arguments given
I solved :
current_changeset = hg id -i
hg update --clean -R repo_path -r current_changeset
Please keep me updated if you have another opinion

Generating patches in Mercurial

I've looked for that in the manual, but I can't generate a patch for the last commit.
I tried
hg qnew patch_name
but it does only file with
# HG changeset patch
# Parent a6a8e225d16ff5970a8926ee8d24272a1c099f9c
I also tried
hg export tip
but it doesn't do anything. I committed the changes exactly.
How to generate a patch file with the last commit in?
The command to do this is export:
$ hg export -o FILE -r REV
It doesn't require redirection and will thus work correctly on any platform/shell.
Your hg export tip is the best way to do it, and the hg diff and hg log based answers are just lesser versions of the same. What exactly do you see/get when you type hg export tip? What does the output of hg log -p -r tip show?
The changeset tip is just means "the changeset that most recently arrived in my repository" which isn't as useful a concept as you might think, since hg pull and hg tag all create changesets too. If you really want the last thing you committed you'll need a more precise revspec.
Like so:
hg diff -r tip > tip.patch
You can use this command:
hg log -r tip -p > tip.patch
this will generate a patch for just that revision.
If you want to convert the latest commit to a patch file, use
hg qimport -r tip
This will replace the topmost regular commit with an applied MQ patch file.
To generate patches using "mq extensions" in mercurial, you can follow the below given steps. This will create a patch using mercurial:
1) Enabling mq extensions: Add the following lines to your hgrc file and save it.
[extensions]
mq =
2) Creating a patch using mq extensions: To create a patch using mq extensions you can do the following.
hg qnew -e -m "comment you want to enter" bug_name.patch
In the above command, -e flag is for editing the patch and -m flag is for adding a message to the patch.
3) Updating the patch: For updating the patch, you can use the following command when a patch is already applied.
hg qrefresh

Accidentally Working on the Wrong Named Branch in Mercurial

I have been making some changes to my working directory, and noticed that I have accidentally been working on the wrong branch. I have not committed anything yet, and I would like my next commit to go against another branch. What is the best way to do this?
The Shelve extension can give you grief, and this can be done entirely with Mercurial commands. Krtek almost had it but he used export instead of diff. Try this:
hg diff --git > ~/saved-work.patch
hg update --clean desiredbranch
hg import --no-commit ~/saved-work.patch
You should be able to just hg up otherbranch. It is important that you do not use the --clean option to hg up, either directly or via an alias as that will discard your uncommitted changes.
Another option is to use one of the extensions that provides hg shelve. The process would then be:
$ hg shelve --all
$ hg up otherbranch
$ hg unshelve
That will create a patch of your changes within the .hg directory, returning your working directory to a clean state, switch to the 'otherbranch', and then apply the saved patch.
I don't know if it is the best solution, but you can follow these steps :
1° hg diff --git > modifications.patch
2° hg update -C the_right_branch
3° hg patch modifications.patch
Maybe it's better to copy modifications.patch somewhere safe, just in case.
edit: update with diff instead of export. Thanks to the commenters.

Mercurial clone from a branch

We have a repository with three named branches, I wanted to clone one of the branches. Is there a mercurial command to do that? If I provide the path (of branch) with hg clone I get 404 error.
hg clone http://your/repo -r branchname should do the trick.
Benjamin's right. But is that really what you want to do? In particular, you'll only get the changesets needed to make up that branch, and nothing else - and that would, for example, prevent you from pulling changesets in from the trunk or other branches. You might well be better off just cloning the entire repository and then simply working in the branch you are interested in; this will let you keep your repository in sync with the one you're pulling from more easily.
hg clone <URL> -b BRANCHNAME clone single branch, as requested
I know that this post is very old, but I had the same question. I found this trick:
hg clone /path/to/your/repo -r 0
hg pull -u -b branchname
I'm using Mercurial-4.0.2. In that we can specify the branch name by appending branch name with a # symbol in the clone url.
e.g.
hg clone https://user#cloneurl/my_product#MY_BRANCH
hg clone --verbose https://user#cloneurl/my_product#MY_BRANCH "C:\myCode"

Pulling changes between two separate Mercurial repositories

I have two versions of a product and am using separate Hg repositories for each. I have made a change to one (v1.0) and I want to pull just that change into the v2.0 repository. How do I go about this? As far as I can tell, using hg pull -f -r xxxxx \\server\hg\v1.0 will pull in all changes up to the specified revision which isn't what I want.
Is this possible or will I have to add the fix by hand?
hg transplant
You can use hg incoming -f -r xxx \\server\hg\v1.0 to reveal what would come in from a pull.
Perhaps the transplant extension will do what you want? Something like hg transplant -s \\server\hg\v1.0 with the interactive changeset selector.
If all else fails, you could use hg diff to pull out a patch for just the revision you want.