2

I need to replace the contents of master with the contents of a branch. I can find details on how to do this in Git, but nothing for Mercurial.

Example Q for Git Replacing master with another branch

My setup is

  • master
  • newbranch

I want the 'master' to be identical to 'newbranch

chendriksen
  • 1,026
  • 6
  • 16
  • 30

2 Answers2

1

The basic choice you have is "rebase or merge": https://blog.sourcetreeapp.com/2012/08/21/merge-or-rebase/

Here on SO, a helpful Q&A is at: Make another branch default?

The remainder of this response borrows from that page.

If you want to close the "feature-branch":

$ hg checkout default
$ hg merge feature-branch
$ hg commit
$ hg checkout feature-branch
$ hg commit --close-branch

The simplicity of the revert/commit approach mentioned there also has much to recommend it:

hg revert --all --rev ${1}
hg commit -m "Restoring branch ${1} as default"

where ${1} is (for example) the name of the relevant branch.

peak
  • 105,803
  • 17
  • 152
  • 177
  • When I do this, it seems to only apply the changes from the branch, rather than overwriting master. Does this make sense? – chendriksen Dec 29 '17 at 09:26
0

Doesn't the first approach assume there are no conflicts between the "default" and "feature branch"? When you desire to replace code, the assumption is that there ARE conflicts, and all should be resolved treating the "feature branch" as authoritative.

pbierre
  • 276
  • 1
  • 8