Git: split pull request into smaller PR’s based upon the new directories in the pull request

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)