Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial Reverting Back, then Reapplying Changesets

Tags:

mercurial

I have commits A, B, C, D, and E. I realize that something very bad happened in commit B, so I want to revert back to A, make the change correctly this time that screwed up B before, and then reapply C, D, and E automatically.

You may be wondering why I don't revert back to B and make the fix there, then remerge back in to E (is this ever a good idea?). The reason is not well understood by me, but it has something to do with the problem occurring in a set of special visual studio files (that should only be edited via some GUI screens in visual studio) that don't play well with simply correcting the file after an error occurred... I would give more details if I knew them

like image 226
Joda Maki Avatar asked Mar 22 '26 07:03

Joda Maki


2 Answers

Just make a backout of what you did in B and commit it as F. This way, history will be intact, and your peers will get the change without having to know about it.

If B is a service release, do make the change there and merge it into F afterwards.

like image 141
Robert Jeppesen Avatar answered Mar 24 '26 19:03

Robert Jeppesen


This can be done using Mercurial Queues (mq). You want to:

  1. Import changesets B through E to mq
  2. Unapply changesets C through E
  3. Fix changeset B and refresh the patch
  4. Reapply C through E
  5. Finalize the patches

This is done as follows:

  1. cd <project>
  2. hg qinit
  3. hg qimport --rev B:E
  4. hg qpop --all
  5. hg qpush <patch name for B>
  6. ...fix the problems you found in B
  7. hg qrefresh
  8. hg qpush --all
  9. hg qfinish --applied

This all assumes that B through E have not been pushed to any public repositories. If they have already been pushed, then your best bet is to simply fix the problem in a new changeset (F).

like image 44
Tim Henigan Avatar answered Mar 24 '26 20:03

Tim Henigan