How to hg unshelve without merge - version-control

Is there a way I can force hg unshelve without causing any merge conflicts? Just overwrite the old files with the shelved state?

Simply use
hg unshelve --tool :other
Using the internal merge tool :other will instruct Mercurial to always prefer the shelved version to local changes. See hg help mergetools for more information on the various internal merge tools.

Related

Reclone mercurial subrepo

This seems like it should be really easy, but I can't find anything that directly addresses it in my searching. I have a mercurial repo with subrepos, I have deleted one of the subrepos (the whole folder). How do I reclone that subrepo now? I could do it manually but surely there's a hg command that does the job?
Use the Clean parameter in your hg update to make it pull the subrepo again.
hg update -C
Beware that clean will discard any uncommitted changes in your working directory, so shelve or commit anything you want to keep before doing it.

Addremove after branch merge?

I work in an environment that has a lot of development across different branches. We use mercurial as source control and often merge branches which contain other features. I am wondering if it would ever be necessary to do hg addremove after a branch merge and before committing?
e.g.:
hg checkout foo
hg merge bar
hg addremove ?
hg commit -m "MERGE: bar -> foo"
Is it perhaps necessary when a changeset that was pulled in added or removed a file, or is this automatically handled by mercurial?
hg addremove is usually not needed during merges. Except when you manually add or remove a file during a merge with conflices where the merge is not automatically handled.
However personally I don't recommend to use hg addremove anyway, especially in merge cases, as I consider it wiser to add and remove files from source control explicitly.

hg: commit a changeset as a merge

Suppose I have two branches A and B. These two branches have been merged together outside of hg (manually I suppose). The merge itself is correct and the files exactly reflect the merge between branch A and B.
Is there a way to commit those files as a merge? I mean to make them appear in hg as if they were merged using hg and make the new commit have both branches as a parent?
One option is to do the merge, but tell hg that you really want that merge to fail. Then reset the files to the version you want and manually mark them as resolved.
hg -y merge --tool=internal:fail otherBranch
hg revert --all --rev thisBranch
hg resolve -a -m
Once you commit and you should be on your way.
See more details here

How to abort a merge in mercurial?

I goofed up a merge. I'd like to revert then try again.
Is there a way to revert a merge before it is committed?
hg revert doesn't do what I'd like, it only reverts the text of the files. Mercurial aborts my second attempt at merging and complains original merge is still uncommitted.
Is there a way to undo a merge after an hg merge command but before it's committed?
hg update -C <one of the two merge changesets>
After you do hg merge, but before hg commit, your working copy has two parents: the first parent is the changeset you had updated to before the merge and the second parent is the changeset you are merging with. Mercurial will not let you do hg merge again as long as your working copy has two parents.
You have two options on how to proceed:
If you want to abort the merge and get back to where you started, then do
hg update -C .
This will update the working copy to match the first parent: the . always denotes the first parent of the working copy.
If you want to re-merge some files then do
hg resolve fileA fileB
This will re-launch the merge tools just as when you did hg merge. The resolve command is good if you find out at hg merge-time that your merge tools are configured badly: fix the configuration and run hg resolve --all. You can run hg resolve as many times as you want until you are satisfied with the merge.
Today there is hg merge --abort. See hg help merge.

Mercurial: How do you undo changes?

When using Mercurial, how do you undo all changes in the working directory since the last commit? It seems like this would be a simple thing, but it's escaping me.
For example, let's say I have 4 commits. Then, I make some changes to my code. Then I decide that my changes are bad and I just want to go back to the state of the code at my last commit. So, I think I should do:
hg update 4
with 4 being the revision # of my latest commit. But, Mercurial doesn't change any of the files in my working directory. Why not?
hg revert will do the trick.
It will revert you to the last commit.
--all will revert all files.
See the link for the Man Page description of it.
hg update is usually used to refresh your working directory after you pull from a different repo or swap branches. hg up myawesomebranch. It also can be used to revert to a specific version. hg up -r 12.
An alternative solution to hg revert is hg update -C. You can discard your local changes and update to some revision using this single command.
I usually prefer typing hg up -C because it's shorter than hg revert --all --no-backup :)
hg revert is your friend:
hg revert --all
hg update merges your changes to your current working copy with the target revision. Merging the latest revision with your changed files (=current working copy) results in the same changes that you already have, i.e., it does nothing :-)
If you want to read up on Mercurial, I'd recommend the very awesome tutorial Hg Init.
hg revert --all
and then
hg pull -u
works for me