nkuhta
nkuhta

Reputation: 11148

Backout many commits (15) in mercurial

I have "test" branch, and I have incorrect 15 commits in it (they are last commits in this branch). I don't need these commits, and I want to back them out. But I also need to have "test" branch, I can't just close it.

All changes exists on remote server. These changes are not last in whole repo, they are last changesets only in test-branch.

Upvotes: 4

Views: 205

Answers (2)

Edward
Edward

Reputation: 3276

If you needed to leave the changesets in history (particularly because you are unable to be certain they can be strip-ed from every repo) you have a couple of options:

1) simply commit a --close-branch the tip of your test branch, update to the last revision that was good on that branch, and reopen your test branch with new commits from there. This works because a named branch can have multiple heads.

2) use hg revert -r <last good rev> and commit. This should make the working directory exactly like <last good rev> and then you can commit the changeset which effectively undoes what happened in the 15 changes you want to remove. I would use hg diff -r <last good rev> to ensure that it is exactly true, since you may need to fix files that had been added or removed.

If you are able to strip the changes from the server (as mentioned in @Dalija's answer), but want to keep a version locally for possible future use, check out hg phase to force the phase to secret locally after strip-ing them from everywhere else. That way you'll still have them, but they won't be pushed by default.

Upvotes: 3

Dalija Prasnikar
Dalija Prasnikar

Reputation: 28512

You can use hg strip for removing changesets and their descendants from repository. But you will have to do that in all repositories where you want to prune your test branch or they will come back when you pull.

https://www.mercurial-scm.org/wiki/StripExtension

Upvotes: 1

Related Questions