How to clean the other commits in Pull Request

Viewed 98

https://github.com/Decimal458/test.git

enter image description here

When I create a PR(#3,#5,#7) to merge "dev/" into "stage", the PR include old commit. enter image description here

But create PR(#4,#6,#8) to merge "dev/" into "main", it would not happend. enter image description here

In the company I work for, those PRs that are merged into the "stage" may contain more commits and even see other people's files in "Files Changed".

I would like to know how to only display my own commits or files when creating a PR that is merged into stage, just like a PR that is merged into main.

Note: I don't have permission to execute merge in the company.

1 Answers

I would like to know how to only display my own commits or files when creating a PR that is merged into stage, just like a PR that is merged into main.

This is all about rebasing --onto: you rebase only your commits on top of the PR target branch, and then force push your feature branch.

That will update the PR, and show only your own commits.

rebase --onto

If you were to make a PR from CVG-xxx to develop, you would see commits from CVG-yyy, because your feature branch was initially create from it.

Assuming CVG-yyy is the commit just before your own CVG-xxx branch:

git fetch
git rebase --onto origin/develop CVG-yyy CVG-xxx
git push --force

The result is: only your own commits are on top of origin/develop now.
Your PR (to origin/develop) will only include your commits.

Related