Bottom Line:
I want to split up a pull request into two smaller pull requests with different subsets of files. I do not want to split by commit, I want to split by file.
Details:
Suppose I have a branch branch_1
(off of the master
branch) in which I've modified 2 files: file_1
and file_2
. Suppose these files were modified together in one or more commits (changes are not separable by commit), and suppose these files do not reference one another in any way.
After some time, I want to merge branch_1
into master
, but decide that only file_1
is ready to be merged. I may merge file_2
later, so I put it on a new branch.
So I create a branch_2
off of branch_1
. branch_2
now contains both the changes to file_1
and file_2
. That's fine, because branch_2
will be merged after branch_1
anyway.
Now, how can I nicely revert branch_1
to remove the changes to file_2
?
If I just go on branch_1
and git checkout master file_2
, it works, BUT: When I merge branch_1
into master
, and then master
into branch_2
, then it will delete file_2
. This is not what I want at all!
Basically I'd like make it as if file_2
never existed at all on branch_1
.
A slightly more convenient way of selecting specific files:
branch_2
from master
branch_1
into branch_2
with --no-commit and --squashbranch_2
Now you can either repeat the procedure again with inverse file selection, completely splitting the two branches right away, or just wait until branch_2
is merged into master
and then merge master
back into branch_1
, effectively "fast-forwarding" those selected files and excluding them from the original branch_1
.
(*) many UI-based git clients offer bulk revert tools, making the procedure quite comfortable
EDIT: added --squash option, as else commits from branch_1
might end up in master
with only a subset of their actual content
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With