开发者

Rolling Back Repository to specific Revission

I have a problem with a repository. I pulled a a list of changesets from another repository, ran the update and merged... The merge didn't work as exp开发者_Go百科ected and now I need to roll back to before I pulled the changesets just to pull them again.

How can I roll back more than one changeset into a specific revision?


If by "roll back" in this context you mean to get rid of the changesets as though you never pulled, then you can use the "strip" function part of the MQ extension.

First enable the MQ extension by editing your .hgrc (*nix) or mercurial.ini (Windows) file:

[extensions]
mq=

Then use the strip command:

hg strip REV

Warning: This will remove the changeset with the given revision hash, and any changesets that follows from that. If you're unsure about what you want to accomplish or how to use the command, make a clone of the repository before you try it, that way you can safely experiment.

Also note that if you've already pushed your merge somewhere else, you have cleanup to do in that repository as well, and depending on whether the merge is "in the wild", it might not be possible to permanently get rid of it.


Rollback isn't what you're describing. If before the pull your repo looked like this:

[A]-[B]-[C]-[D]

and after the pull it looked like:

[A]-[B]-[C]-[D]
          \
           -[E]-[F]

and after the merge it looked like this:

[A]-[B]-[C]-[D]-----[G]
          \        /
           -[E]-[F]

then you don't want to undo the pull -- you still want changesets E and F -- you just want to take another try at the merge, G.

There are a few ways to do that. The most Mercurial way to do that is to just do:

hg update D
hg merge E
... re-merge, doing it better this time ...
hg commit # creates H

Then your history will look like:

[A]-[B]-[C]-[D]-------- [G]
          \          X
           -[E]-[F]-----[H]

where that X is a crossing. You'd then use H as your new point of development and ignore (or close G).

Second best it to remove G and then re-do the merge. The official way to do that is to clone your repository locally getting everything except G like this:

cd ..
hg clone -r tip-1 myrepo mynewrepo

where you'll then have everything in mynewrepo except for G. You can then re-merge. The strip command also works, but it's disabled for a reason.

The bottom line is you don't need to remove and redo the pull; just the merge.


I haven't really used mercurial, only really CVS and SVN, but it should be the same. I'm presuming that you can checkout an older version based on the revision number or date, correct? If so, check out the older version in a temporary directory and re-merge that. You will need to delete any new files added in the repository though as well. That way you should effectively have the same copy of the files as 2 or more revisions ago.

This will have the same effect as rolling back, though it will be a higher revision number. The same contents, just a newer revision. I think this is the safest way to do it, as there's no way of loosing anything.


If you want to return to a specific revision and discard all local changes, you can simply update to the revision and pass the clean flag:

hg up -C -R 7

This line discards uncommitted changes and reverts to revision 7, as an example.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜