3

I have searched here, but haven't found any question related to this. I got a problem like this in mercurial: I manage open source project in bitbucket, so i have clone of the source code in my local. But I also using that project for my own live site, so I made 2 clone of bitbucket repo

Bitbucket Repo
|
==local_clone1
|
==local_clone2-> commit1            => commit2    => commit3
                (personalization)     (bug fix)     (add feature)

The question is, I want to push commit2 and commit3 back to local_clone1, so later on I can push to Bitbucket repo. But don't want to push commit1, since it has my personal data.

Wondering how we do that in mercurial?

5
  • I'm also interested in the answer, but you probably would not get in stuck if you were using feature branches (named branch per feature/bug fix)
    – zerkms
    Nov 15, 2010 at 3:56
  • You're going to get a lot of answers below about how to work around this, but going forward you're better off avoiding it, and you do that by controlling the parentage of your changesets. If commit2 and commit2, which don't rely on commit1, had as their parent the parent of commit1, then you could easily push using push -r commit3 and commit1 wouldn't go. The key is to ask yourself "what is the earliest changeset that could be this commit's parent" and update to that before creating the changeset. Branches, etc. are just abstractions to make remembering to do that a little easier. Nov 15, 2010 at 5:12
  • @zerkms : For this problem, I can't use branch, since if we want to push commit2 and commit3, we need to merge the branch, in which commit1 will also get merged and pushed to bitbucket
    – hudarsono
    Nov 15, 2010 at 8:06
  • @Ry4an : still don't really understand your solution. But if we do push commit -r3, then all the ancestors which are commit1, commit2, commit3, will be pushed all together. Whereas we don't want commit1 be pushed
    – hudarsono
    Nov 15, 2010 at 8:28
  • 1
    if the commit before commit1 is commit0, then Ry4an is saying, update to commit0 before doing commit1 and again before doing commit2 (because commit2 doesn't depend on commit1). Then you effectively have 2 branches: commit0 -> commit1 and commit0 -> commit2. You can push commit2 without pushing commit1, and in your local clone, can merge commit1 and commit2 to get all your changes combined. The same applies to commit3 if it doesn't depend on commit2. Nov 15, 2010 at 10:16

2 Answers 2

5

This can be done without too much difficulty in this case. See Removing history in the Mercurial guide for more information.

Here's the basics of what you'll need to do:

  • Go to local_clone2
  • Get the revision number (hg tip will show you) from the current number. We'll call it 731.
  • hg export 730-731 > ../local_clone1/changes.diff (or wherever you like)
  • Go to local_clone1
  • hg import changes.diff

You may need to edit things manually; refer to that guide for more info in that case.

4
  • Note that this will of course make new changesets with the same content, but different hash id's, which means a simple pull later and you now have merge conflicts. Nov 15, 2010 at 7:54
  • True; for that reason you'd be best advised to throw away local_clone2 and clone afresh (or rollback the three revisions). Nov 15, 2010 at 8:50
  • Wow, thanks alot. This solution works for me. Since i manage that open source only to allow people to clone, not to commit. SO, no need to worry pull problem. This just works.
    – hudarsono
    Nov 15, 2010 at 9:31
  • What was meant was if you tried to pull to local_clone2. No one else will have those extra three revisions, so that's not an issue elsewhere. If you're satisfied this works, you can mark it as the accepted answer. Nov 15, 2010 at 9:34
1

Here are a couple of options:

backout

Given a history constructed as:

hg init db
cd db
echo >file1
hg ci -Am clone              # rev 0
echo >file2
hg ci -Am personalization    # rev 1
echo >file3
hg ci -Am bugfix             # rev 2
echo >file4
hg ci -Am feature            # rev 3 <tip>

Then if the current working directory is the tip, the following commands will "undo" the personalization revision:

hg backout 1
hg ci -m backout

The advantage is history remains immutable, but shows the addition and backout of the personalization changeset.

Mercurial Queues

With the mq extension, history can be edited to remove a changeset:

hg qimport -r 1:3  # convert changesets 1-3 to patches
hg qpop -a         # remove all patches (can't delete an applied patch)
hg qdel 1.diff     # delete rev 1's patch
hg qpush -a        # reapply remaining patches
hg qfin -a         # convert all applied patches back to changesets.

The advantage is the personalization changeset disappears. The disadvantage is the changeset hashes change due to the history edit, so this should never be done to changesets that have already been pushed to others. There is also the risk of a mistake editing history.

3
  • This is probably the correct way to go, but yeah, if you have already shared your changes, you're in for some more work down the line. Nov 15, 2010 at 7:55
  • Hm, this solution at the moment, doesn't really fit the need, if we manage open source project. Since the histories still there, so every one that clone our project will see all the histories which contain our personal data.
    – hudarsono
    Nov 15, 2010 at 9:32
  • Did you read the 2nd option? The history is removed with that one. Nov 15, 2010 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.