Search code examples
gitgithubgithub-actionsgit-branchconventional-commits

Will deleting specific commits from a branch affect the original branch it was created from?


I have a branch A that was created from another branch B. Some specific commits from branch B are also present in branch A. I’m considering deleting those commits from branch A, but I’m concerned about whether this will also delete them from branch B.

  1. If I delete commits from branch A, will those commits be deleted from branch B as well?
  2. Is there a way to make branch A fully independent from branch B so I can remove commits without affecting the original branch?

For context:

  • I’ve squashed some commits on branch B.

Solution

    1. No, Branch A is derived form Branch B and when you delete them it won't effect the "Parent Branch".

    2. You can use this code git rebase --onto [newParent] [oldParent] [branchToMove]

    • rebase - Change the parents of something
    • --onto - This is the flag that tells git to use this alternate rebase syntax
    • newParent - This is the branch that the branch you are rebasing will have as it's parent
    • oldParent - This is the branch that the branch you are List iterebasing currently has as it's parent
    • branchToMove - This is the branch that you are moving (rebasing)

    I hope it helped you.