开发者

Use case for private changes

开发者 https://www.devze.com 2023-01-05 16:59 出处:网络
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. No

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 separa开发者_JAVA百科te 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?


Instead of tags, I would use a bookmark. If you use Mercurial 1.8 or later, you already have the bookmark functionality built-in. Otherwise, you first have 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消