I have a number of changes that I committed to my local repository, but have not yet been pushed. Since on a feature is taking longer than expected, I want to swap these changes onto a named branch before I push. How can I do this?
Move branch start in Mercurial
My problem is similar to Mercurial move changes to a new branch, but is not exactly the same. A colleague of mine started working on a new feature and issued a few local commits. Then he noticed Oh w
Move current changes to a new branch without initial commit
I did some (uncommited) changes on a new feature on my project and I noticed that the work on it will be more than I thought. So I decided to move these changes to a new branch. If I create a new bran
Proper way to move stable branch changes back to main in Mercurial
in Mercurial after you have created a stable branch, say RC1, from the main dev branch, you keep on working on the dev branch for future versions. Now if you are required to make quick fixes on RC1, w
How to move some changeset to a new branch in mercurial
I want to move a changeset from one branch to another. Basically, I currently have: A -> B -> C -> D # default branch And I want: A # default branch /-> B -> C -> D # some_new_branc
SVN: Move pending changes to a new branch
SVN is freaking me out right now. I’ve got some changes pending, that should not be comitted to the trunk, but rather to a branch that does not yet exist. I don’t even manage to create a branch at all
Moving uncommitted changes to a new branch [duplicate]
Possible Duplicate: Move existing, uncommited work to a new branch in Git I have some code in branch ABC. After making some changes to it, i’d like to move all those uncommitted changes into a comm
git move uncommited changes from master to new branch
There are solutions to similar problems in stackoverflow. But I wanted to make sure my question falls in the same category: I did a git checkout master I made some changes(uncommitted) and realized th
Git: move changes off of master branch
Basic question but this happens to me all the time: Make changes in a working-branch Switch to master git merge working-branch git push cap deploy(to staging) make a new cup of tea then I come
Mercurial – close default branch and replace with a named branch as new default
In a mercurial repo, the default branch has fallen very out of date to the point where it no longer makes sense to merge in the changes from develop, a named branch which has the latest deployed v
Committing changes to a new branch and leaving the current branch clean? [duplicate]
This question already has an answer here: Move existing, uncommited work to a new branch in Git 1 answer I have a bunch of changes in a branch that I didn’t commit yet. They ended up getting mo
You can use the MqExtension. Let’s say the changesets to move are revisions 1-3:
hg qimport -r 1:3 # convert revisions to patches hg qpop -a # remove all them from history hg branch new # start a new branch hg qpush -a # push them all back into history hg qfin -a # finalize the patches
As suggested by Mark, the MqExtension is one solution for you problem. IMHO a simpler workflow is to use the rebase extension. Suppose you have a history like this:
@ changeset: 2:81b92083cb1d | tag: tip | summary: my new feature: edit file a | o changeset: 1:8bdc4508ac7b | summary: my new feature: add file b | o changeset: 0:d554afd54164 summary: initial
This means, revision 0 is the base on which you started to work on your feature. Now you want to have revisions 1-2 on a named branch, let’s say my-feature. Update to revision 0 and create that branch:
$ hg up 0 $ hg branch my-feature $ hg ci -m "start new branch my-feature"
The history now looks like this:
@ changeset: 3:b5939750b911 | branch: my-feature | tag: tip | parent: 0:d554afd54164 | summary: start new branch my-feature | | o changeset: 2:81b92083cb1d | | summary: my new feature: edit file a | | | o changeset: 1:8bdc4508ac7b |/ summary: my new feature: add file b | o changeset: 0:d554afd54164 summary: initial
Use the rebase command to move revisions 1-2 onto revision 3:
$ hg rebase -s 1 -d 3
This results in the following graph:
@ changeset: 3:88a90f9bbde7 | branch: my-feature | tag: tip | summary: my new feature: edit file a | o changeset: 2:38f5adf2cf4b | branch: my-feature | summary: my new feature: add file b | o changeset: 1:b5939750b911 | branch: my-feature | summary: start new branch my-feature | o changeset: 0:d554afd54164 summary: initial
That’s it .. as mentioned in the comments to Mark’s answer, moving around already pushed changesets generally is a bad idea, unless you work in a small team where you are able to communicate and enforce your history manipulation.
I prefer the patch solution describe here by Mark Tolonen
What I have:
hg log -G #default branch @ changeset: 3:cb292fcdbde1 | o changeset: 2:e746dceba503 | o changeset: 1:2d50c7ab6b8f | o changeset: 0:c22be856358b
What I want:
@ changeset: 3:0e85ae268e35 | branch: feature/my_feature | o changeset: 2:1450cb9ec349 | branch: feature/my_feature | o changeset: 1:7b9836f25f28 | branch: feature/my_feature | / | o changeset: 0:c22be856358b
hg export -o feature.diff 1 2 3 hg update 0 hg branch feature/my_feature hg import feature.diff
Here is the state of my local repository
@ changeset: 6:0e85ae268e35 | branch: feature/my_feature | o changeset: 5:1450cb9ec349 | branch: feature/my_feature | o changeset: 4:7b9836f25f28 | branch: feature/my_feature | | o changeset: 3:cb292fcdbde1 | | | o changeset: 2:e746dceba503 | | | o changeset: 1:2d50c7ab6b8f |/ | o changeset: 0:c22be856358b
Now I need to delete the revisions 1 2 and 3 from my default branch. You can do this with strip command from mq’s extension. hg strip removes the changeset and all its descendants from the repository.
Enable the extension by adding following lines to your configuration file (.hgrc or Mercurial.ini):
vim ~/.hgrc and add :
[extensions] mq =
And now strip this repository on revision 1.
hg strip 1
and here we are
@ changeset: 3:0e85ae268e35 | branch: feature/my_feature | o changeset: 2:1450cb9ec349 | branch: feature/my_feature | o changeset: 1:7b9836f25f28 | branch: feature/my_feature | o changeset: 0:c22be856358b
note: changesets are different but revisions are the same
For those inclined to use GUI
- Go to Tortoise Hg -> File -> Settings then tick rebase .
Restart tortoise UI
Create new branch where you will be moving changes. Click on current branch name -> choose Open a new named branch -> choose branch name.
- If changes you want to move have not been made public (e.g draft) go to 5. (If changes have already been published and you are not a senior dev you should talk to someone senior (get a scapegoat) as you might screw things up big time, I don’t take any responsibility 🙂 ).
Go to View -> Show Console (or Ctrl + L) then write in console hg phase -f -d 2 – where 2 is lowest revision you will be moving to new branch.
Go to branch and revision (should be topmost revision if you are moving changes to new branch created in step 3.) Right Mouse -> Update
Go to branch and revsion you will be moving changes from Right Mouse -> Modify History -> Rebase
Click Rebase and pray there are no conflicts, merge if you must.
Push changes, at this point all revisions should still be draft.
Go to topmost revision in branch you were moving changes to Right Mouse -> Change Phase to -> Public.
Hope this saves you some time.