Can I create a Git Pull Request that only includes commits for an individual developer or work item?

I would like the ability to build a Pull Request that includes commits from each developer or a specific work item. I typically create a branch for each work item that I am addressing. But I often find that additional commits (from other developers and work items) appear when I create a Pull Request.

For example, I have a commit that consists of changes to one-and-only-one file. When I do a Pull-Request, the Pull-Request balloons to an additional four commits with an additional 40 files.

My steps are below.

  1. Create a new local branch from my remote master branch.
  2. I edit one-and-only-one existing file.
  3. I save my changes to the edited file.
  4. I Push my change from my local branch to the origin branch. This creates a commit with changes to the one-and-only-one file.
  5. I do a Pull Request.

I now have four additional commits and a total of 41 files.

Is there a way to build Pull Requests to include only commits for an individual developer?

I would also like to use a separate branch; specifically for merging commits from multiple developers and work items.

Are there third-party tools that are especially good at allowing developers to remove commits from a Pull Request? I'm especially interested in a tool that would simplify Git and reduce the time lost to Git issues.

1 answer

  • answered 2020-07-29 17:25 eftshift0

    The problem there is that you started working from a branch that is different from the branch that you are asking your PR to be merged into.... that's why you see those other revisions. You might skip this problem by rebasing your branch... suppose that it's called X and you want to merge it into origin/master:

    git rebase --onto origin/master X~1 X
    git push --force origin X # replace the old X on the server with the new X

    Now the PR should only contain your revision.