I've been dabbling with Mercurial for a short while now, and I've now set up several projects on BitBucket, one forking off of the other.
I've been able to make changes to each repo with no problem, but one thing I can't figure out, is how to keep the fork up-to-date with changes from the parent repo?
After I've forked a repo, I only see the commits from that repo up to X revision, after which point I only see the fork's own commits, no new parent commits.
I'm pretty certain that during my dabbling with git, I was able to rebase to the latest parent revision, but that was awhile back and I'd rather not guess my way into bad habits :-)
Just perform the pull with the source repository as an argument. It will pull all the changes done after your previous pull (or from the time you forked the project, if no pulls were performed).
After that you will have some additional heads, which you have to merge with your ones.
Here are 3 essential steps:
hg pull -u path_to_parent
hg merge
hg commit -m"updates from parent"
Or you could install fetch extension that combines all these steps:
hg fetch path_to_parent
Related
I have a repository called 'Myproject' and within that we have a branch "MyProject-new changes"
I have cloned the "MyProject" repository in my local machine as
c:/MyProject
and similarly cloned "MyProject-new changes" as
c:/MyProject-new changes"
Both the repositories have the latest changes after pull and merge.
Now, I need the changes from "MyProject-new changes"(branch) changes merged into "MyProject" locally.
Once I merge, I don't want to commit these changes..I will revert back the changes as the branch changes are being worked. I just want to integrate the new changes and see the results for time being.
Please let me know the following
How do I merge locally the code from "MyProhect-new changes" to "Myproject"
How do I revert back MyProject once I tested it.
So you need a test site where you can test merge. Usually people create separate clone for experiments. This gives you easy way to revert changes — just delete experimental clone. So lets start from making another clone of MyProject and update on the latest commit in branch default.
Suppose revision 25 is the latest revision in branch default. You can update on it with command hg up -r 25.
Suppose revision 37 is the latest revision in MyProject-new changes. You can merge latest changes from MyProject-new changes into branch default with command hg merge -r 37. After that you'll have merge result in your working directory.
Since you work in the separate clone you can commit without doubt. Commit with hg ci -m 'merge with new changes' and test the result. When you finished your tests you can simply delete experimental clone.
The simplest way is to make a complete clone of your repository, merge and test to your heart's content, and throw out the repository when you're done. #Kirill explains how to do that.
But why do that? Maybe you'll come across problems, or small merge conflicts, that you'll fix in the clone. It will be a pity to throw away this work-- you'll probably need it in the future. You could simply keep the clone around, of course, but I suggest reconsidering your premise: Why don't you want to merge the two branches?
You have a main branch (default) and a feature branch new-changes, and you want to safely see how they work together. Here's two ways you can do this without cloning the repository:
To keep the default branch safe, simply merge from default into new-changes:
hg update new-changes # switch to the branch
hg merge -r default
You can now test new-changes and fix any problems. This is a very common workflow: Changes to default are incorporated into long-running branches to keep them from drifting too far apart. When you're eventually ready to unify the two lines of development, merge new-changes into the default line and everything will work correctly.
If you want to keep both branches pure for the time being, you can create a new branch testing and merge both existing branches into it. You can keep it around and eventually merge it into default, or close it if new-changes turns out to be a failed experiment. (Detail: If testing is rooted at the head of one of the branches, there'll be "nothing to merge" from that branch. You'll only need to merge the other one.)
If you don't want to risk messing up your main repo, you can of course clone it and try one of the above approaches on the clone. Once you're satisfied that it worked correctly, push everything back to the main repo.
My co-worker and I are working on a project and we are using mercurial + bitbucket.
We are experiencing problems when one of us pulls from bitbucket and merge. For instance, after I pull from bitbucket with hg pull --rebase, I have to
remove files that were removed in previous commits
modify files that were modified in previous commits
move files/folders that were moved in previous commits
He does hg pull followed with hg merge and gets the same results as me.
What are we doing wrong?
Besides rebase/merge, we work the same
work, work, work
pull rebase/merge
fix merge issues
push
The most likely cause is that you're rebasing changesets that have already been pushed. Rebase modifies history, and unless you really know what you're doing you should only rebase changesets that have never been shared to another repository.
If you are using Mercurial 2.1 or later it has support for phases. When phases are working rebase will only allow rebasing of draft and secret changesets, not public ones.
In general, I'd advise you to use merging rather than rebasing.
I faced today my first mercurial problem. I was in my repo, I modified a file and I did a
hg commit
hg pull
followed by
hg update
hg rollback
to repair what I've done, (but actually I didn't push anything)
The problem is that when I did the pull (that I should do before the commit, the head changed and so hg heads looks like :
- Modif from yesterday
- My modif
- Modif from last week
and now I see that someone also did another modification (via the http interface). What should I do to repair my local repo, (if possible modifying my summary) and push it after the 2 others modifications.
Thanks a lot. Quiet confusing, was easier on my "one-man" repo..
Your local repo doesn't need "repairing". This is a very standard case that you will see often if you use Mercurial a lot.
The issue is multiple heads.
You can either merge your heads, assuming your working directory is your version and there is only the other head:
hg merge
This will result in a merge changeset (same as if you were merging across branches).
Or you can enable the rebase extension to re-base your version onto the tip of the branch (the other head):
hg rebase --source<YourVersionNumber> --dest<TipVersionNumber>
This will not result in a merge changeset, and will simply transplant your changes on top of the changeset you specify as if they were born of that changeset all along (hence rebase or "new"basing).
Multiple heads is a funny sort of inner-branch branching... you can continue checking stuff in against your own head and change between heads using hg update. We block multiple heads per branch on our server, so our push would fail. I'd advise keeping multiple heads local as they are less clear-cut than branches.
I tend to work with Mercurial in one of two ways:
If the work is large in scale I will branch it off and follow Continuous Integration practices (constantly merging the main branch into my own etc). I then re-merge back into main when I am happy with the end result.
If the work is small in scale I will simply work against main branch and "merge" heads every so often. I say "merge" as I usually use rebase. Re-basing works great if the changes are simple and conflicts are unlikely.
My hard and fast rule: if I can't use rebase I put it on a branch born of main.
I'm in my branch, and I do this:
hg incoming /path/to/baseline
And I get a few changesets in the output.
Now do I just merge to pull in the changsets to my branch?
hg merge /path/to/baseline
Will my history show what was merged?
As long as I didn't touch those files, it will be automatic right?
You should really try all this out yourself! Make a couple of test repositories:
hg init main
hg clone main clone
and then experiment away. It's easy and safe since you're only playing around on your own machine. (This is actually what happens "behind the scenes" when you ask a question here: I try to make sure that the advice I give really works, so I normally have to run a few tests on a new repository to double-check.)
If you ran the tests, you would see that
You cannot give hg merge a path name (or URL) as argument. It takes a revision as the only argument. You need to hg pull /path/to/baseline to copy the changesets into your local repository and then hg merge.
The history will indeed show what was merged. A merge becomes a merge commit in Mercurial. That is a changeset with two ancestor changesets — both lines of development leading up to the merge are still in the repository.
Merges are without conflicts ("automatic") if the changes made in the two branhces don't overlap. If you edit different files in the two branches then there's certainly no overlap. But you can also edit different regions within the same file and still have a merge without conflicts.
There is a fine tutorial on the wiki and I've also written a beginners guide. I hope that helps.
I have a hg clone of a repository into which I have done numerous changes locally over a few months and pushed them to my clone at google code. Unfortunately as a noob I committed a whole bunch of changes on the default branch.
Now I would like to make sure my current default is EXACTLY as upstream and then I can do proper branching off default and only working on the branches..
However how do I do that cleanup though?
For reference my clone is http://code.google.com/r/mosabua-roboguice/source/browse
PS: I got my self into the same problem with git and got that cleaned up: Cleanup git master branch and move some commit to new branch?
First, there's nothing wrong with committing on the default branch. You generally don't want to create a separate named branch for every task in Mercurial, because named branches are forever. You might want to look at the bookmark feature for something closer to git branches ("hg help bookmarks"). So if the only thing wrong with your existing changesets is that they are on the default branch, then there really is nothing wrong with them. Don't worry about it.
However, if you really want to start afresh, the obvious, straightforward thing to do is reclone from upstream. You can keep your messy changesets by moving the existing repo and recloning. Then transplant the changesets from the old repo into the new one on a branch of your choosing.
If you don't want to spend the time/bandwidth for a new clone, you can use the (advanced, dangerous, not for beginners) strip command. First, you have to enable the mq extension (google it or see the manual -- I'm deliberately not explaining it here because it's dangerous). Then run
hg strip 'outgoing("http://upstream/path/to/repo")'
Note that I'm using the revsets feature added in Mercurial 1.7 here. If you're using an older version, there's no easy way to do this.
The best way to do this is with two clones. When working with a remote repo I don't control I always keep a local clone called 'virgin' to which I make no changes. For example:
hg clone -U https://code.google.com/r/mosabua-roboguice-clean/ mosabua-roboguice-clean-virgin
hg clone mosabua-roboguice-clean-virgin mosabua-roboguice-clean-working
Note that because Mercurial uses hard links for local clones and because that first clone was a clone with -U (no working directory (bare repo in git terms)) this takes up no additional disk space.
Work all you want in robo-guice working and pull in robo-guice virgin to see what's going on upstream, and pull again in roboguice-working to get upstream changes.
You can do something like this after the fact by creating a new clone of the remote repo and if diskspace is precious use the relink extension to associate them.
Preface - all history changes have sense only for non-published repos. You'll have to push to GoogleCode's repo from scratch after editing local history (delete repo on GC, create empty, push) - otherwise you'll gust get one more HEAD in default branch
Manfred
Easy (but not short) way - default only+MQ
as Greg mentioned, install MQ
move all your commits into MQ-patches on top of upstream code
leave your changes as pathes forever
check, edit if nesessary and re-integrate patches after each upstream pull (this way your own CG-repo without MQ-patches will become identical to upstream)
More complex - MQ in the middle + separate branches
above
above
create named branch, switch to it
"Finish" patches
Pull upstream, merge with your branch changes (from defaut to yourbranch)
Commit your changes only into yourbranch
Rebasing
Enable rebase extension
Create named branch (with changeset in it? TBT)
Rebase your changesets to the new ancestor, test results
See 5-6 from "More complex" chapter
Perhaps you could try the Convert extension. It can bring a repository in a better shape, while preserving history. Of course, after the modifications have been done, you will have to delete the old repo and upload the converted one.