Forcing or redefining mercury merging?

When I do "hg heads", I see two heads.

I want to just accept the changes from the first and completely ignore the other.

Is this what hg push -f does?

How can I tell mercurial to simply ignore the second head?

+4
source share
2 answers

This page provides three different ways to get rid of branches, but it will also work for heads. Branch is created when changeset has more than one child. Named branches can be created using the hg branch command, however unnamed branches can be created (either by mistake or by designation) by making two sets of changes for the same parent.

For example, if I create a new repository, add a file to it and commit that commit will changeet 0.

 hg init # create repo # edit file myfile.txt hg add myfile.txt hg ci -m 'added myfile.txt' # creates changeset 0 

Then I make a few more changes and commit them again, creating changeet 1 whose parent is change set 0.

 # more edits to myfile.txt hg ci -m 'changed myfile.txt' # creates changest 1, with parent changeset 0 

Now for some unknown reason, I go back to change set 0, make some changes to myfile.txt, and commit them.

 hg up -C 0 # update to changeset 0 # more edits to myfile.txt hg ci -m 'edited myfile.txt' # creates changeset 2, who parent is also changest 0 

Now we have done something strange. We returned to change list 1 and made various changes. We returned on time to our code and changed something by creating an alternative universe, as in BttF Part II!

Well, not really. We really created a branch. However, this is an unnamed branch, since we did not create it using the hg branch command (and therefore do not appear in hg branches). He also created a new head . Heads are simply changes without children, so any branch, named or unnamed, that has not been merged or closed, will have a head.

This is a contrived example and may not be what you did. What is more common if you work in two places and forget to press when you do it in one place, or pull when you start work in another place again. If you don’t click when this is done in one place, when you start work in 2nd place, you can work on an older set of changes, and thus, any commits will create a second head. This happens when you forget to pull.

As I said earlier, this creates an unnamed branch. However, you can view this branch just like any other branch. The hg update branch_name simply updates you to the title of this branch, so for an unnamed branch, you can simply update the head of this unnamed branch with hg update head_revision and hg heads to display the heads for you (or hg heads -v if you need more information about each head).

I would recommend just closing your head that you no longer want (the first option is on the first link above). So it still exists just in case you need it later, but it does not appear in hg heads . To do this, run the following commands:

 hg up -C head_to_close hg commit --close-branch -m 'Closing un-wanted head' hg up -C head_to_keep 

You will need to figure out which head you want to close. hg heads -v will provide you with additional head information. You can also upgrade to each hg up head_changeset and examine the code to find out which one you want to close.

+3
source

This tip covers her well:

https://www.mercurial-scm.org/wiki/TipsAndTricks#Keep_.22My.22_or_.22Their.22_files_when_doing_a_merge

If you upgraded to the one you want, you will run:

 hg --config ui.merge=internal:local merge #keep my files 

You do not want hg push -f .

+5
source

Source: https://habr.com/ru/post/1346135/


All Articles