I am trying to combine two repos but I get error "repository is unrelated"..
Any workaround ?
hg pull -f /other/repo
You're probably familiar with repos that have multiple heads. They can have multiple tails too!
Related
I have a bunch of files, its actually a c# project and the files related to it, the whole hg repository is a solution with many projects.
I need to move those (with history) to another existing repository .
What is the best way to do this?
Say, you have A and B repositories. Your goal is to extract an 'a' folder in A and merge it with B to make B_with_a, while preserving histories.
1) Extract 'a' in A and make Aa. You can do this with hg convert:
~$ hg convert A Aa --filemap list.txt
where list.txt is
include a
2) Pull Aa to B - to make B_with_a_yet_merged. You have to use -f since they are not related.
~/B$ hg pull ./../Aa -f
3) Merge two branches in B_with_a_yet_merged to make B_with_a
~/B$ hg merge (with the last rev in Aa)
PS.
Don't forget to backup A and B beforehand! When I first did this, I messed up repositories three times.
After a poke around hg commands I found bundle, seemed to have made the trick. More details soon
Update: tried this and didnt work. It brought the files when I unbundled it, and I was able to merge, but for some reason the graph was off.
I just thought I d post for completeness
When I have to commit merges I've done in mercurial, I just do hg commit -m "Merge."
What do you usually do when Merging? Do you write the changesets in a comment, or try to write "meaningfull" comments (since I think they are useless, except when you're doing merges from two really different repos in different locations).
Is it possible to create an alias in mercurial (like hgmerge) in [alias] in hgrc, that automatically does hg commit -m "Merge: heads ${head}, ${head} ..."?
It would be easy to create that alias (I'll do it below) but it's also of almost no value. It's very easy to pull the parent1 and parent2 values out of a merge changeset, so it's not really telling you anything more than just "merge" would.
Personally, even on single person repos I try to put something at least halfway useful even if it's just something like these:
merging configuration work into code
merging work from desktop into work from laptop
merging away an anonymous branch I didn't like
forgot to pull/update before editing
There's always some reason history diverged, even if it's a totally mundane reason like forgetting to update or working disconnected at the coffeeshop, and that's what I note.
That said you could do this:
hg commit -m "merging: $(hg parents --template '{node|short}\n') | xargs"
which you sould make a shell alias with:
[aliases]
mycommit = !$HG hg commit -m "merging: $(hg parents --template '{node|short}\n') | xargs"
Allowing you to run hg mycommit, but just dig for the better description.
P.S. Someone is going to suggest the fetch extension. Ignore them.
When I'm merging after a pull, I usually only write something like "merge after pull". When I must correct something after the merge, I'll precisely describe what I did so my coworkers can understand the changes.
When I'm merging a branch in another, I precise the two branches on the commit message "merging branch1 in branch2".
As for the alias, sorry, I have no idea.
I am using Mercurial Queues on a repository, and have placed those patches in a patch repository. Another contributor has cloned my patch queue and made changes of their own. I would now like to merge their changes in my local patch repository.
I am trying to find a good workflow for performing this merge that
reflects the contributor's changesets in the history of the patch repository
invokes the user's merge tool in case of conflicts
Initially, I just tried to merge the patches directly. This is okay in very simple cases, but does not work well when many things have changed, since the patches depend on line number context which doesn't seem like something I should have to worry about adjusting myself. Overall, I find examining a 3 way diff of patches to be too complex.
Is there a better way?
There's no great way to handle this. What I'd probably end up doing is creating two clones, and qfinishing your patch in one and the contributers patch in the other. That that point you'll have repos with each separate patch's net effect applied. Then you hg pull one of those clones into the other, and hg merge will let you use your graphical tools to merge the results of the patches -- and the only differences should be the differences in your patches. At this point, ideally, you'll be able to qimport the merge changeset, but you can't do that, so you have to 'hg diff -r tip-1 -r tip' to get a new diff that is the difference between before-everything-started and after-merging-the-two-results. You then 'qimport` that diff and commit it to your patch queue repo with a note saying where it came from.
Decidedly sub-optimal, but the best I can come up with. I'd love to hear a better solution.
I'm afraid that there is no automated way to merge patches.
However, one "trick" you can use is to create new patches instead of editing/refreshing existing patches when you need to amend them. When you all agree on the right way to do things, then hg qfold the patches.
That way you wont be stepping on each others toes as much since you create new patches.
I've encountered a problem in my Mercurial workflow when experimenting with implementing a certain feature. I was trying three different approaches to implementing the feature by commiting each update followed by updating to the previous changeset - so I end up with three different branches.
Once I have chosen one of the branches to be the "correct" implementation of the feature, I want to remove the other branches so that I don't have multiple heads. How do I do this in a simple way? I ended up merging the three branches together which was pointless because I only ever wanted the code from one branch.
In addition to hg strip from the mq extension, you can simply use the standard clone command:
$ hg clone -r the-good-head . ../pruned
to get a clone in ../pruned that holds only the good head (and all its ancestors). This is the safe, built-in way to prune things in Mercurial and it has the advantage that you still have both repositories intact after the command. So if you make a mistake, then just delete the ../pruned clone.
The following closes a branch
hg commit --close-branch
It will not show up in
hg branches or hg heads
Enable the built-in mq extension and run hg strip.
#pyfunc's answer keeps the closed branches in revision history, which is what I would actually do unless your unwanted branches are huge.
I have two separate mercurial repositories. At this point it makes sense that they "become one" because I want to work on the two projects simultaneously.
I'd really like the two projects to each be a subdirectory in the new repository.
How do I merge the two projects?
Is this a good idea, or should I
keep them separate?
It seems I ought to be able to push from one repository to the other... Maybe this is really straight forward?
I was able to combine my two repositories in this way:
Use hg clone first_repository to clone one of the repositories.
Use hg pull -f other_repository to pull the code in from the other repository.
The -f (force) flag on the pull is the key -- it says to ignore the fact that the two repositories are not from the same source.
Here are the docs for this feature.
hg started to have subrepo since 1.3 (2009-07-01). The early versions were incomplete and shaky but now it's pretty usable.
If you aren't using the same code across the projects, keep them separate. You can set your personal repository of each of those projects to be just a directory apart. Why mix all the branches, merges, and commit comments when you don't have to.
About your edit: Pushing from One repository to Another. You can always use the transplant command. Although, all this is really side stepping your desire to combine the two, so you might feel uncomfortable using my suggestions. Then you can use the forest extension, or something.
hg transplant -s REPOSITORY lower_rev:high_rev