'Forgetting' a dead-end branch

走远了吗. 提交于 2019-12-06 09:55:04

Personally I'd close the branch and force the push (as Tim Henigan describes), as it leaves the DAG in a state which is truthful. There is another option though. Doing a dummy merge. This is a merge, but one where you ignore the incoming changes.

hg update C
hg -y merge --tool=internal:fail B
hg revert --all --rev .
hg resolve -a -m
hg ci

The end result is

M
|\
C |
| |
| B
|/
A

... but M doesn't contain any of B's changes.

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.

Use the backout command to reverse the B change.

hg up B
hg backout B

Now, you're working directory is in the same state it was before B, which I'll call A'.

After you backout, make your real change and commit. This is what your history will look like:

C
|
A' 
|
B
|
A

Mercurial branches are permanent and registered in commit objects themselves. There are some (not too easy) methods for closing and/or removing branches, mainly listed here. I have even already used some of them before. Note that those are somewhat desperate solutions for people who did use branches thinking they can be temporary.

However, if you really want temporary branches, use bookmarks.

Other people have some good answers for getting rid of 'B', but just to put it out there you can always do:

hg push --rev C

which will push C but not B and not complain about new heads.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!