hudarsono
hudarsono

Reputation: 389

mercurial push certain revision

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?

Upvotes: 3

Views: 1718

Answers (2)

Mark Tolonen
Mark Tolonen

Reputation: 177665

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.

Upvotes: 1

Chris Morgan
Chris Morgan

Reputation: 90752

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.

Upvotes: 5

Related Questions