0

I have created a branch from mybranch-1 instead of develop and then made a lot of commits on that new branch. Is there a way to remove the commits/changes made on mybranch-1 without removing the commits/changes made on my new branch ?

SCHYNS Anthony
  • 343
  • 2
  • 7
  • So `mybranch-1` is the name of that new branch. And you'd like to remove the commits/changes made on mybranch-1 _without_ removing the commits/changes made on the new branch? - I'm confused – evolutionxbox Jul 15 '22 at 08:38
  • Yes sorry for the bad explanation. mybranch-1 is not my new branch, it is another branch that I was working on and has its own commits. I have created mynewbranch from mybranch-1 by mistake (I wanted to create it from my develop branch) so now I want to remove to remove mybranch-1 commits from mynewbranch if it is possible ? Is it enough clear ? Sorry I'm not good at GIT – SCHYNS Anthony Jul 15 '22 at 08:47

1 Answers1

0

Assuming that your local branches looks like it:

   A---B---C---F---G (dev)        
            \
             D---E (mybranch-1)
                  \
                   H---I (newbranch)

  And you want to achieve:

   A---B---C---F---G (dev)        
                    \
                     H---I (newbranch)

The command you are looking for is git rebase --onto

For your case it will be git rebase --onto dev mybranch-1 newbranch

You can read more about said command on: How to git rebase a branch with the onto command?

Small note: The said command will remove commits that are on mybranch-1 from newbranch, and will rebase newbranch with dev branch.

kadewu
  • 336
  • 4
  • 8