Domanda

Let's say I've got two Mercurial branches: (1) default and (2) stable. I push bugfixes to stable and new functionality to default. Every now and then when enough functionality has been added to default, default gets merged into stable. Stable then gets tagged with a decent tag. For the sake of simplicity, let's just say I use the tags 1.0, 1.1, 1.2, 1.3 etc.

Now, let's say I release stable with the tag 1.3. I then go on with development, and later on release 1.4 and 1.5. It then comes to my attention that a major bug exists in 1.3 (and 1,4 + 1.5), and I need to fix that one. How do I best go back to 1.3, fix that bug, and make sure that the bug also gets applied to 1.4 and 1.5?

As I'm talking about tags, and not branches, is this possible at all? From the top of my head, I'd say that I would somehow need to roll back to stable's 1.3 tag, fix the bug and then push the bug to 1.3 (and then forward-port the bugfix to 1.4 and 1.5). However, rolling back to a tag is essentially the same as rolling back to a revision. Is it even possible to roll back to a previous tag/revision and apply changes to that "point in time"?

How do I best solve this?

È stato utile?

Soluzione

However, rolling back to a tag is essentially the same as rolling back to a revision. Is it even possible to roll back to a previous tag/revision and apply changes to that "point in time"?

There is nothing that stops you. You can checkout any revision and start a new head from there on by simple doing a commit. Only when pushing your changes Mercurial will stop you when you push a branch with multiple heads (unless the --force options is used). But you would not want to push multiple heads anyway because the bugfix commits are supposed to get merged into the main stable and default heads.

From the top of my head, I'd say that I would somehow need to roll back to stable's 1.3 tag, fix the bug and then push the bug to 1.3 (and then forward-port the bugfix to 1.4 and 1.5)

Yes, that's the basic idea. Let's create a bugfix merge cascade!

Supposed you have a history like this:

@  changeset:   7:83f16f6d167d (tip)
|  summary:     new feature bar
|
| o  changeset:   6:c20d6c330271 (stable)
| |  summary:     Added tag v1.1.0 for changeset fd09feac2b59
| |
| o  changeset:   5:fd09feac2b59 (stable) (v1.1.0)
|/|  summary:     merge default into stable
| |
o |  changeset:   4:38ace577cfb7
| |  summary:     new feature foo
| |
| o  changeset:   3:0581117b05f7 (stable)
| |  summary:     Added tag v1.0.0 for changeset 5305c84aeebb
| |
| o  changeset:   2:5305c84aeebb (stable) (v1.0.0)
|/   summary:     new branch stable
|
o  changeset:   1:a8bf2fb0f30a
|  summary:     new features
|
o  changeset:   0:c70ef214ec57
   summary:     initial

That is you have 2 release on the stable branch: v1.0.0 and v1.1.0. Now you have that urgent bug to fix and you need the fix for both revisions and of course also in your default branch. Here's what I would do:

$ hg up v1.0.0
... fix the bug ...
$ hg commit -m 'fix that bug in v1.0'
$ hg tag v1.0.1
$ hg up v1.1.0
$ hg merge tip
... the merge  will raise conflicts in `.hgtags` ...
... make sure the resolved version contains the content of both sides ...
$ hg commit -m 'merge bugfix into v1.1'
$ hg tag v1.1.1
...

Do this until all releases have the bugfix merged in. Finally, also merge the bug fix into the original head of your stable branch and into the default branch.

$ hg up c20d6c330271
$ hg merge tip
$ hg commit -m 'merge bugfix into main head of stable'
$ hg up default
$ hg merge stable
$ hg commit -m 'merge bugfix from stable into default'

Now the history looks like this:

@    changeset:   13:358084bd1a91 (tip)
|\   summary:     merge bugfix from stable into default
| |
| o    changeset:   12:a12c5c10d9db (stable)
| |\   summary:     merge bugfix into stable
| | |
| | o  changeset:   11:e78d7ea72624 (stable)
| | |  summary:     Added tag v1.1.1 for changeset abd62a5ba092
| | |
| | o    changeset:   10:abd62a5ba092 (stable) (v1.1.1)
| | |\   summary:     merge bugfix into v1.1
| | | |
| | | o  changeset:   9:8f272cc5a565 (stable)
| | | |  summary:     Added tag v1.0.1 for changeset 21f31836b80c
| | | |
| | | o  changeset:   8:21f31836b80c (stable)
| | | |  summary:     fix that bug in v1.0
| | | |
o | | |  changeset:   7:83f16f6d167d
| | | |  summary:     new feature bar
| | | |
| o | |  changeset:   6:c20d6c330271 (stable)
| |/ /   summary:     Added tag v1.1.0 for changeset fd09feac2b59
| | |
| o |  changeset:   5:fd09feac2b59 (stable) (v1.1.0)
|/| |  summary:     merge default into stable
| | |
o | |  changeset:   4:38ace577cfb7
| | |  summary:     new feature foo
| | |
| o |  changeset:   3:0581117b05f7 (stable)
| |/   summary:     Added tag v1.0.0 for changeset 5305c84aeebb
| |
| o  changeset:   2:5305c84aeebb (stable) (v1.0.0)
|/   summary:     new branch stable
|
o  changeset:   1:a8bf2fb0f30a
|  summary:     new features
|
o  changeset:   0:c70ef214ec57
   summary:     initial

Note that the bugfix has been committed ony once, but merged it into all revisions and branches where it is needed.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top