Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

taking uncommitted changes on the wrong branch to the right branch

Tags:

mercurial

I am using Mercurial.

I have some uncommitted changes but I am on the wrong branch, how do I update to the right branch and take the changes with me?

like image 771
jrwren Avatar asked Nov 03 '11 20:11

jrwren


People also ask

How do you take uncommitted changes from one branch to another?

Create a new feature branch, say feature, and then switch to that branch. Implement the feature and commit it to our local repository. Push to the feature branch to the remote repository and create a pull request. After other teammate's review, the new change can be merged into the master or release branch.


2 Answers

For uncommited changes you can use the Shelve extension:

  1. hg shelve --all
  2. hg up correct_branch_name
  3. hg unshelve
like image 178
Rafael Piccolo Avatar answered Sep 29 '22 04:09

Rafael Piccolo


I asked on irc

mpm said

hg diff > mychanges; hg up -C somewhere; hg import --no-commit mychanges

which I had considered but is what I was trying to avoid.

d70 said

i think you can easily do it by "hg update"ing to a changeset that is a
parent of the branch you're trying to switch to, and then "hg update"ing to the
tip of that branch

so I did that.

hg up -r <shared root rev>
hg up branchIwant

I asked about "why" and was told "you are not allowed to update across branches" which didn't make sense to me at first. Then I realized that because I went through the shared root rev, it isn't across branches.

like image 32
jrwren Avatar answered Sep 29 '22 06:09

jrwren