Dan
Dan

Reputation: 57961

Is it possible to create a branch when having uncommitted changes?

In Mercurial repo:

1) I've checked out (updated) from default

2) I've edited something

3) I've realized I need a branch to experiment with my edits

4) When I try to create a branch Mercurial claims I have uncommitted changes

If I don't get mistaken, in git allows you to checkout -b in such situation. I need to create a branch and commit my changes there.

UPDATE

It turned out that hg is as smart as git, and ALLOWS creating branches when having uncommitted changes. So, the problem on step 4 had no relation to hg.

Upvotes: 0

Views: 1087

Answers (1)

Ry4an Brase
Ry4an Brase

Reputation: 78350

This works just fine for me:

ry4an@four:~$ hg init dan
ry4an@four:~$ cd dan
ry4an@four:~/dan$ echo text > afile
ry4an@four:~/dan$ hg commit -Am added
adding afile
ry4an@four:~/dan$ echo more >> afile
ry4an@four:~/dan$ hg branch newbranch
marked working directory as branch newbranch
(branches are permanent and global, did you want a bookmark?)
ry4an@four:~/dan$ hg commit -m another
ry4an@four:~/dan$ hg log
changeset:   1:84b54b473852
branch:      newbranch
tag:         tip
user:        Ry4an Brase <[email protected]>
date:        Wed Dec 04 11:36:52 2013 -0500
summary:     another

changeset:   0:b07d96580927
user:        Ry4an Brase <[email protected]>
date:        Wed Dec 04 11:36:13 2013 -0500
summary:     added

When I ran hg branch newbranch nothing was actually created. The hg branch command just tells Mercurial what branch the next commit should be on, and indeed when I did that commit the log shows it was on newbranch. I had uncommitted changes when I did the hg branch line and there was no warning or error saying I couldn't do it -- how, specifically, are you trying to create that branch?

Upvotes: 3

Related Questions