Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github: split PR into two PRs by files

Tags:

git

github

Here's an operation that's trivial in Perforce and seems nigh impossible in Git, but let's see. Situation: Pull Request with six files, call them: A, B, C, X, Y, and Z. None of this is merged to master, but the local branch has been pushed to the remote (Github if it matters).

There are many, many commits that touch any and all of these files. Some commits touch only one file. Some touch all six.

I want to create two new PRs. One PR contains files A, B, and C with all the changes from all the commits. The other PR contains X, Y, and Z with all the changes to those files from all the commits. I don't care what happens to the commit history or branches. All commits will be squashed before merge and all work branches will be deleted.

like image 236
Elliotte Rusty Harold Avatar asked Jul 19 '26 02:07

Elliotte Rusty Harold


1 Answers

I was in a similar situation as you and this is what I did :-

  1. Checkout your feature branch.
  2. Considering that your master branch is named as main, run git reset --soft main. This will delete all your commits in your feature branch. But all the changes that you did in those commits will stay as unstaged files.
  3. Now, create a new branch. Stage files A, B and C. Commit, push and create a new PR. This PR will contain changes only from files A, B and C.
  4. Checkout your original feature branch again. Again, create a new branch. This time, stage files X, Y, and Z. Commit, push and create a new PR. This PR will contain changes only from files X, Y, and Z.
  5. Close your original PR (that contained changes from all 6 files) as it is no longer required and ask reviewers to review the 2 new PRs that you created.
like image 79
Omkar Rajam Avatar answered Jul 21 '26 16:07

Omkar Rajam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!