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.
Related
mq, which I like a lot, but which I understand is being deprecated in favor of changeset evolution, provides a command hg qdiff that shows the combination of the last-saved patch mixed with the current working directory diffs. I.e., it shows what will be the content of the complete patch if I enter hg commit --amend right now.
Is there a way to show the combined diff like that in base (non-mq) mercurial?
I realized the answer as I prepared to submit the question: hg diff with respect to the parent of the current change:
hg diff -r '.^'
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>
In Git it is easy, because remote/branch is pointing to a different commit than branch. How to do it with Mercurial?
If you mean seeing what's different between your local repo and the one you're pushing to, try
hg outgoing
Since Mercurial 2.1, there is also a purely local solution: phases. The draft phase is probably what you are looking for. For details, refer to:
https://www.mercurial-scm.org/wiki/Phases
You may find hg phase <rev> and hg log -r "draft()" interesting.
There is an remotebranch extension that will give you a Git-like setup. It tracks the remote heads for the repositories listed in the [paths] and exposes them as tags named <path>/<branch>. This lets you run
$ hg diff -r foo/default
to see what has changed since the default branch in the foo repository. There is also new revset keywords that let you do things like
$ hg log -r "not pushed()"
to get what
$ hg outgoing
would do, but without any network traffic.
What's the command line call to show all revisions in the draft phase?
hg log --style phases
That will display the log + the phase, since Mercurial 2.7 (2013-08-01).
I'd just use hg outgoing as others are suggesting, but hg summary will tell you too. It may require the --remote option to have it check the remote default server.
If you need to select the changesets for further processing, then you can use the outgoing revset predicate. This lets you re-implement hg outgoing as
hg log -r "outgoing()"
but the real benefit is that you can use this in other contexts, such as
hg strip "outgoing()"
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.
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"