Home > Mobile >  Removes changes from another branch GIT
Removes changes from another branch GIT

Time:07-15

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 ?

CodePudding user response:

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.

  • Related