Question

I created a branch and committed a changeset as a child of a child of my main branch. I actually meant to shelve the changes and create a new branch off of my main branch. How can I revert and/or make the branch a direct child of my main branch?

I have a hunch that I will need to revert or do a subtractive merge.

Was it helpful?

Solution

For PlasticSCM, the idea would similar to what is described below for Git:

  • having a branch referring to your current commit
  • reset the branch to the last correct commit
  • use the switchbranchbase command mention for PlasticSCM4 or the simple merge mention in this thread.

    • In PlasticSCM 3.0 to perform a rebase the steps were: Change branch base, update, merge.
    • In PlasticSCM 4.0 is easier, just perform the merge from the branch you want to rebase.

Original answer in git:

If you have:

 x--x--x--x                 main
           \
            y--y--y         child
                   \
                    z--z    mybranch

You can do a:

git rebase --onto main child mybranch

That would give you:

            z'--z'          mybranch
           /
 x--x--x--x                 main
           \
            y--y--y         child

If you didn't want to rebase all of my branch, then a simple:

git checkout mybranch
git branch -b mynewbranch
git reset --hard z          # reset mybranch HEAD to the last commit before your new commit
git rebase --onto main mybranch mynewbranch

For a single commit, you could also use git cherry-pick, but I always prefer git rebase.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top