I have a monolith of a feature branch. Instead of one massive PR into master I would like to split it up into 3 prs.
Ideally I want to pull out some standalone code from the feature branch into a PR by itself. This code is in a new directory and isn't called into yet so it would be a relatively safe PR. However instead of just copying the directory and creating a single commit and PR I would like to retain all the commit history of the changes for the new PR.
Is this possible using Git? I've looked into filter-branch but it seems like that is for splitting a repo into two, not for splitting a diff of changes into two (if that makes sense).
To split it into multiple PRs, locally, we do the following: $ git checkout migrate-to-firebase $ git reset --soft develop $ git restore --staged . First, we checkout the branch and then we uncommit all the changes that do not exist on develop without removing the changes themselves.
There are no rules for how you split the shares between the work's creators. If you are published, you will have to agree the splits with your publisher before either of you register the work. If you are a member of PRS, your publisher can receive no more than 50 percent of the share.
is there a way to pull files out of a branch including their commit history into a new branch?
You pull a commit, meaning a whole repo into a branch, not just some files.
One good option would then be to reset the files you don't want to their content pre-branch
--x--x--x (master) \ y--y--y (branch B1 with mixed work) \ z (new branch B2, but with some files reset to master)
B2
starts from B1
and include the files you want, with their history.
But B2
also includes other files from B1
that you would like to be as master
.
You can do (in B2
) a git reset --soft master
: a git status
would tell you all the changes you need to do in order for your index to reflect master. Simply don't add changes that involves the files you want to keep by using git restore -- path/to/file
(restore
instead of checkout
, since Git 2.23, Aug. 2019). And don't commit. You just want to stage changes back to master
for some files.
(See also "Practical uses of git reset --soft
?")
Once that is done, a git reset --soft B2
moves HEAD back to B2
(but with an index recording all the changes and deletions necessary to reflect master for the right files).
You can commit now, with the other files reverted to master
and the files you want untouched, identical to B1
, with their history intact.
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