Mercurial via TortoiseHg - Merge a named branch then close it
Asked Answered
K

5

32

I have a named branch, NewFeature, that I made off of the default branch. I've made a couple commits to that branch, and now I'd like to merge it to rejoin the default branch.

Now (each letter is a commit):

   default: A---B
NewFeature:      \--C---D

What I'd like:

   default: A---B-----------E
NewFeature:      \--C---D--/

I tried right clicking the directory and selecting "Hg Commit...". I then selected "Close Current Named Branch". I got this error: abort: can only close branch heads

I also looked for a "close branch" option in the repository explorer, but I couldn't find anything.

Could someone please help? Thanks in advance!

Edit: I posted an issue to TortoiseHg

Kilburn answered 1/2, 2011 at 0:5 Comment(0)
S
24

To merge, you need a clean working copy - no uncommitted changes. The merge will be placed in the working copy for review and then you commit the working copy to "complete" the merge.

If you have uncommitted changes you are not prepared to commit, you can see about shelving those changes temporarily (if you have that appropriate extension) or checkout a new working copy somewhere else to use for the merge.

Using the Repository Explorer:

  1. Update the working copy to rev B.

  2. Select rev D row in the revision history.

  3. Right-click on rev D and choose Merge with.... The dialog should show rev B should be the local rev and D should be the other rev.

  4. Click Merge in the merge dialog and resolve any conflicts, if any.

Up to now, nothing has been changed in the repository - your merge is in the working copy. So if something is wrong, you can cancel the merge, revert your working directory, and start over at later time or after making some other additional branch or trunk changes.

If everything is good after steps 1-4, click Commit in the merge dialog to commit the merge.

Swindle answered 1/2, 2011 at 0:41 Comment(2)
If You also really need to mark branch "NewFeature" as closed, proceed one additional step before step 1 of Bert F recipie: Staying in working copy on revision D choose "Close current branch" from dialog, which You can open from branch selector at center of a line with button "Commit", write note like "NewFeature done" and press "Commit".Nutation
After that You can merge this closed branch to branch "default" as described below by Bert FNutation
M
44

The example you give is more a Merge than really a Close. Also, if it's that simple, you probably don't want/need to create a named branch.

But if you really want to close a branch through TortoiseHg, eg

  1. you created the NewFeature branch
  2. then both the Default branch and NewFeature branches were modified
  3. then if the NewFeature branch takes quite some time you might have also already merged several time Default into NewFeature (to avoid having too many differences when you'll want to finally merge the NewFeature branch into the Default one)
  4. eventually your new feature is entirely implemented or stable enough, you merged the NewFeature branch into the Default one

From now on, no one is supposed to commit anything on the NewFeature branch, so you'd like to close it.

You can do so in TortoiseHg (I have version 2.3.2):

  1. click Hg Commit... when you are on your NewFeature branch (no need to have anything to commit - or you do it with your final merge)
  2. click "Branch: NewFeature" (it's at the top in bold)
  3. select "Close current branch".
Mok answered 8/5, 2012 at 2:22 Comment(3)
This helped me, but I guess it must look different between version 2 and 3. I had to click in the dialog box where you would enter a commit message for step 1, although perhaps that's what you meant.Lasseter
It may have been different back then, but you actually have to press "commit" (and then push) so that the branch is actually closed (currently using Tortoise 6.5.1 but years ago it was the same procedure).Carmon
@TheincredibleJan Don't hesitate to update my answer with an updated version of TortoiseHg. I've switched to TortoiseGit years ago, so I don't know how the current interface looks like.Mok
S
28

For anyone that's confused by the answers to this question, here are the instructions on how to do this from within the TortoiseHg Workbench:

How to Merge Feature Branch and Close Branch

  1. Open TortoiseHg Workbench.
  2. Select your repository from the Registry Repository.
  3. Switch to the branch that you would like merge your branch into (default in this example):

Switch to the default branch

  1. Right mouse click the branch that you'd like to merge and close (NewFeature in this example) and choose Merge with Local. This will merge the branch changes from the NewFeature branch into default:

Merge one branch into another

  1. You will see a confirmation box that confirms that your changes will be merged from one branch to another, click through the steps Next, Commit Now and Finish:

Confirmation box

  1. Now you can see from the Graph that the changes have been merged in, we can now close the NewFeature branch as we no longer need it:

Branch merge graph

  1. Update your local to the branch you would like to close, in this case it is NewFeature:

Update to branch to close

  1. Click commit, the big green tick at the top of the workbench. Big green tick

  2. In the commit window, you should see the branch that you want to close above the comment text box. Click the branch name:

Commit window with branch name we want to close

  1. A window will pop up and select close current branch:

Close current branch

  1. Now click commit. Your graph should show that the branch is closed:

Graph showing closed branch

Strive answered 23/1, 2018 at 14:44 Comment(0)
S
24

To merge, you need a clean working copy - no uncommitted changes. The merge will be placed in the working copy for review and then you commit the working copy to "complete" the merge.

If you have uncommitted changes you are not prepared to commit, you can see about shelving those changes temporarily (if you have that appropriate extension) or checkout a new working copy somewhere else to use for the merge.

Using the Repository Explorer:

  1. Update the working copy to rev B.

  2. Select rev D row in the revision history.

  3. Right-click on rev D and choose Merge with.... The dialog should show rev B should be the local rev and D should be the other rev.

  4. Click Merge in the merge dialog and resolve any conflicts, if any.

Up to now, nothing has been changed in the repository - your merge is in the working copy. So if something is wrong, you can cancel the merge, revert your working directory, and start over at later time or after making some other additional branch or trunk changes.

If everything is good after steps 1-4, click Commit in the merge dialog to commit the merge.

Swindle answered 1/2, 2011 at 0:41 Comment(2)
If You also really need to mark branch "NewFeature" as closed, proceed one additional step before step 1 of Bert F recipie: Staying in working copy on revision D choose "Close current branch" from dialog, which You can open from branch selector at center of a line with button "Commit", write note like "NewFeature done" and press "Commit".Nutation
After that You can merge this closed branch to branch "default" as described below by Bert FNutation
D
1

In TortoiseHg, your working copy must be updated to the tip of the branch you want to close before using the commit dialog.

Closing a branch will create a new changeset on top of the branch tip.

The error you described (abort: can only close branch heads) typically occurs if you have updated to a changeset not at the tip of a named branch.

Dittmer answered 1/2, 2011 at 0:17 Comment(2)
I already did. To make sure, I right clicked the "D" commit in the repository explorer and selected "Update..." (with "discard local changes"). I then right clicked the repository directory, selected "Hg Commit...", and chose "Close current named branch". I hit commit, and the same error popped up.Kilburn
@sharoz: My next step would be to try this from the command-line. hg --debug commit --close-branch -m "Closing branch". If the debug output doesn't tell you anything, then I would try a hg update --clean just to be absolutely sure.Dittmer
T
1

You also seem to get this error is the branch is already closed, i.e. trying to close a closed branch. A more helpful error message would be useful.

Tonnage answered 20/8, 2015 at 11:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.