How can I control the "return" of a bookmarked branch in mercurial?

I have an open source bitbucket project. Recently, I have been working on an experimental branch that I (for some reason) did not create for the branch itself. Instead, I used bookmarks.

So, I made two bookmarks in the same version

  • test - the new code I was working on should now be left (due to experiment failure)
  • main - stable old code that works

I worked in a test. I also clicked from the test on my server, which eventually switched the tip tag to the new unstable code, when I really would prefer it to stay on the main one. I β€œswitched” back to the main tab by doing hg update main and then making a minor change. So, I pressed this with hg push -f , and now my original control is β€œright” on the server.

I know that there should be a cleaner way to "switch" branches. What should I do in the future for this kind of operation?

+4
source share
2 answers

tip not a commonly used term in a repository that has branches of any type. Regardless of whether you use bookmarks, named branches, or anonymous branches, tip always means the most recent commit on any branch, which rarely bothers you. The real solution to your problem is to stop worrying about tip !

+1
source

I do not understand your question, since you switch branches (without quotes), even if they are not called branches, they are still branches when you use bookmarks.

The error you had was an honest mistake, and I don’t see Mercurial protecting you from this again with bookmarks (marking the same turn with different bookmarks and making the wrong settings). However, I can tell you how to do private local branching with Mercurial , and that way you can avoid the consequences you just had:

You use named branches and phases

Mercurial Phases are really sweet, let me explain them very quickly. You can note changes in three special states called phases, and these are secret, draft, and public.

  • a secret . Do not click. It can be changed by editing the story.
  • draft : click. It can be changed by editing the story. This is the default state for any version.
  • public : click. Throws a warning when using extensions for editing history (strip, rebase, histedit, ...).

As already mentioned, all local versions of the default draft, when you click them, become public . You can use the hg phase command to mark changes for a specific phase, but if you go from # 3 to # 2 or from # 2 to # 1 (according to the previous numbering), you need the -f argument to force this change:

secret β†’ draft β†’ public

To go left, you need to use --force or -f.

Here is what you do:

 hg branch experiment hg commit -m "Opening experimental branch" //say this creates revision 123 hg phase -sf tip //s is for secret, f is for force //... hack hack hack hg commit -m "Uh oh screwed up here" hg push //no secret revisions are pushed 

Now you can simply abandon this branch and leave it that way, it will never be forced. Forget about it and even just close it so that it does not bother you when you list your branches. He will not push, he will not be on the list, so just do not worry about it.

However, if you have an OCD, just split the ( hg strip ) branch into a commit where the branch was opened and it disappeared:

 hg strip 123 

If you already have a branch, you can change several of these changes several times:

 hg phase <start revision>::<end revision> -sf 

To make your secret project or publish it, just follow the last revision phase of these steps:

 hg phase -d tip //assuming you are in the experiment branch 

Then click and the branch will become public.

Mercurial is increasingly getting better at modifying a story without changing its overall philosophy that prevents it. Phases are designed to protect against accidental modification of a story, as well as from sharing what you do not mean.

How * i * use bookmarks

Personally, I use bookmarks for debugging and when I want to try two different ways to do one. Bookmarks are useful to me when you want to make anonymous branches (update the previous revision, fix and fork history), but want everything to be clear.

0
source

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


All Articles