views:

46

answers:

1

Supposing I have following scenario: I cloned some open-source project, say from URL X. Now I have local clone of it.

I made some changes to local clone to try things out and commited them locally. Now what I want is following:

I want to get update from the open-source project X. Just get all its latest code, without my changes at all. But I want my changes to live somewhere in tag in history so I can get them later. And I don't want to separate clone for this, want it all in my one repo.

For now I did following:

  1. Tag my changes with hg tag
  2. Pull & merge latest code from URL X
  3. Revert repository to latest revision of URL X

But I feel this isn't good way and it's roundabout. I think there's better way. Could you please suggest? Thank you

+3  A: 

Instead of tags, I would use a bookmark. You first enable the extension by putting the following in your ~/.hgrc file:

[extensions]
bookmarks =

[bookmarks]
track.current = True

Now get the clone of your project:

hg clone http://bitbucket.org/user/X
cd X

and hack away:

# edit, edit, edit...
hg commit -m 'Great new feature!'

Now put a bookmark on this changeset

hg bookmark mywork

This is like a tag, but the advantage of a bookmark is that is moves along when you make new commits. This is just like when you're reading a book and move the bookmark along with you. When the bookmark is created, you can do

hg update mywork

to get back to the bookmarked changeset.

When there has been changes made in the upstream repository, then you pull and merge them into your own branch:

hg update mywork # if necessary
hg pull
hg merge
hg commit -m 'Merged new upstream changes.'    

The bookmark will have moved forward and is now pointing to the merge changeset you just created. If you want to update to the version in X, then

hg update --rev -2

will do it after you pulled in changes -- this updates to the old tip changeset from before the merge, which was the tip of X.

Martin Geisler
Thank you, but bookmark is just improved tag here, right? I mean, maybe what I was looking for it is hg update --rev? instead of revert?
zaharpopov
zaharpopov: oh, I read your "Revert repository to latest revision of URL X" as meaning `hg update` with the latest revision of X. Please read the help for both commands -- the short version is that `hg update` updates file content *and* changes the working copy parent revision whereas `hg revert` only updates files.
Martin Geisler
@Martin: thanks
zaharpopov