1

I have a git branch related question.

For example, from the origin/master codebase, I switch to a branch, b1:

git checkout -b b1

Here, I update the code, then commit the changes.

Then, I switch to another branch, b2:

git checkout -b b2

Here, b2 depends on b1, b2 can see b1's changes; so based on b1's code, I further modify the code-base, commit the changes.

My question is: Can I just push the code change in b2, without the changes in b1?

Note: in my condition, I don't want to push the changes in b1.

Thanks

MyCoy
  • 61
  • 5
  • Question here... Couldn't you just revert the changes you don't want to have in the master branch that are present in b1 branch? If so, then instead of creating a sub-branch of b1, 'b2', you just merge b1 (without the code you'd like to omit) directly to master. – Carlos Parra May 03 '18 at 01:17
  • [Very similar question asked recently.](https://stackoverflow.com/questions/50144367/git-branching-pull-request-on-head-branch-takes-also-prior-branch-commits/50144819) – Frax May 03 '18 at 01:18

1 Answers1

2

Not directly: you need to replay b2 on top of origin/master (assuming that none of b2 change depends on b1 changes, or your prooject won't compile)

git checkout b2
git rebase --onto origin/master b1
git push
# if you had already pushed b2:
git push --force

Note that if b2 was already pushed and used by other collaborator, that would rewrite its history: you need to warn your colleagues.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250