Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3356676
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:32:29+00:00 2026-05-18T02:32:29+00:00

My question is this: If I have two heads (branches with changes) in my

  • 0

My question is this:

  • If I have two heads (branches with changes) in my Mercurial repository, and I’d like to get rid of one of them, but discard all the changes from that branch instead of merging them into the other, and I can’t strip out those changesets so I have to merge, how can I do that with the command line client?

If I have two heads in my Mercurial repository, and use TortoiseHg as my client, the repository might look like this:

two heads

Then I can get rid of the test2 head by doing a merge and discarding. First I would update to the head I’d like to keep (test3 in this case, which in the image above is already the current parent of my working folder). Then I would right-click and select “Merge with…”:

merge with...

and in the dialog that pops up I would choose to discard the changes from the merge target (ie. the branch I’d like to discard all the changes from):

merge dialog

After this merge has gone through, all the changes in the test2 head has been discarded, and I can commit. The head has now disappeared, but the changeset is still part of history.

My question is this: How can I do the same thing using only the command line client? I can’t find any matching options to the hg merge command:

hg merge [-P] [-f] [[-r] REV]

merge working directory with another revision

... snipped text

options:

 -f --force       force a merge with outstanding changes
 -t --tool VALUE  specify merge tool
 -r --rev REV     revision to merge
 -P --preview     review revisions to merge (no merge is performed)
    --mq          operate on patch repository

use "hg -v help merge" to show global options

Edit: debugsetparents worked nicely:

hg debugsetparents . 1
hg commit -m "merged to get rid of changeset #1"


Edit: Attempt to use the --tool internal:local according to one of the answers:

@echo off

setlocal
if exist repo rd /s /q repo
hg init repo
cd repo

rem revision 0
echo >test1.txt
hg commit -m "test1" --addremove

rem revision 1
echo >test2.txt
hg commit -m "test2" --addremove

rem revision 2
hg update 0
echo >test3.txt
hg commit -m "test3" --addremove

rem now let's get rid of change in revision 1 with merge
hg merge --tool internal:local -r 1
hg commit -m "merged"

dir

output of execution:

[C:\Temp] :test
adding test1.txt
adding test2.txt
0 files updated, 0 files merged, 1 files removed, 0 files unresolved
adding test3.txt
created new head
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)

 Volume in drive C is unlabeled      Serial number is 0e17:6aba
 Directory of  C:\Temp\repo\*

16.11.2010  20:05             .
16.11.2010  20:05             ..
16.11.2010  20:05             .hg
16.11.2010  20:05              13  test1.txt
16.11.2010  20:05              13  test2.txt
16.11.2010  20:05              13  test3.txt
                39 bytes in 3 files and 3 dirs    12 288 bytes allocated
    66 600 316 928 bytes free

Here the changes introduced in the 2nd changeset (the one with revision number 1), is now present in the merged changeset. This is not what i wanted.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:32:30+00:00Added an answer on May 18, 2026 at 2:32 am

    According to TortoiseHG’s source, when you check Discard all changes from merge target (other) revision, it uses the hg debugsetparents command:

    hg debugsetparents REV1 [REV2]
    
    manually set the parents of the current working directory
    
        This is useful for writing repository conversion tools, but should be used with care.
    
        Returns 0 on success.
    
    use "hg -v help debugsetparents" to show global options
    

    To use:

        hg up <revision-to-keep>
        hg debugsetparents <revision-to-keep> <revision-to-throw-away>
        hg commit -m "Merge to discard ..."
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be a bit of a silly question but; If I have two
Background This question is in two parts. I have a one-way WCF operation hosted
This question is related to this one . I have two Android projects inside
I have two tables (well, two relevant for this question) : Bets (holds the
Actually, this question seems to have two parts: How to implement pattern matching? How
Now I have seen this question in another forum but it didn't had an
I have this question: Does implementing a custom MembershipProvider class needs you to implement
The responses I've got to this question have solved the problem I had in
I am new to C and i have this question. why does the following
I have seen this question: Are there any decent UI components for touch screen

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.