smeeb
smeeb

Reputation: 29537

Moving unstaged + uncommitted changes between Mercurial branches

I cloned a Mercurial repo and did a bunch of local work, and forgot to make a feature branch for said work.

The normal flow is:

  1. Clone
  2. Create a branch
  3. Switch to that branch
  4. Do your work in that branch
  5. Push that branch
  6. Code review
  7. If code review passes, merge branch w/ default (locally)
  8. Push merged changes to default
  9. Close the feature branch

So I need to create a new branch, port all my unstaged/uncommitted code changes (made to default) over to this branch (so that default is now clean and the new branch contains my changes), and then push my feature branch.

I created the new branch via hg branch new_feature. But after pouring over the Merucrial docs, I can't figure out the next step.

So I ask: How do I move (not just copy) all my unstaged/uncommitted changes from default to my new_feature branch)?

Upvotes: 0

Views: 774

Answers (1)

Lasse V. Karlsen
Lasse V. Karlsen

Reputation: 391506

You shouldn't have to do anything in particular.

Your uncommitted working folder changes are fluid, and you can set the branch name before you commit, without losing your changes.

If you're on the command line, simply do this:

hg branch feature-X
hg commit -m "Added feature X"

If you're using TortoiseHg simply click the "Branch: default" button just above the commit message input field and select "Open a new named branch" and give it a name, then click OK, then commit as normal.

Setting the branch name to use during commit does not in fact change your working folder, it doesn't do an update, it doesn't do anything, except record in metadata what the branch name is supposed to be.

Also note that this will only allow you to create a new branch to commit to. If you want to continue on an existing branch you first need to update to the head of that branch and this may cause changes to your working folder. You should not need to do this, however, if you want to create a new branch.

Upvotes: 2

Related Questions