Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Forgetting' a dead-end branch

I've got a mercurial repository. It was on rev A. I made some changes, committed (to rev B), and pushed. However, later, I realised I didn't want to make those changes. I updated back to rev A, and made some alternative changes, to rev C.

C
| -
| B
|/
A

However, now I can't push rev C, because it complains that it would create a new remote head (which it would). How do I make the remote mercurial simply forget about rev B and all the changes therein, so I can push rev C and carry on from there?

like image 734
thecoop Avatar asked Jun 09 '26 06:06

thecoop


1 Answers

Editing History is hard. Once you push a changeset to a public repository, it can no longer be easily pruned from the history.

The most direct solution to your problem is:

  1. hg update <tip of branch you want to forget>
  2. hg commit --close-branch -m "close unwanted branch"
  3. hg update <tip of branch you want to keep>
  4. Push all your changes. As you noted, you will need to use --force since multiple heads on the branch now exist.

If you really need to prune the branch, then read EditingHistory again. If it still seems feasible, you can use one of the methods described in PruningDeadBranches.

like image 198
Tim Henigan Avatar answered Jun 12 '26 10:06

Tim Henigan