git提PR时很多别人的commit,清理多余的commit

在自己的分支上git pull后git push提PR时,有时除了自己的commit,会把很多别人的commit也带进去,因为自己的分支落后主分支太多

如何把提的PR里很多别人的commit清除掉?

git checkout mybranch
git fetch origin main
git rebase origin/main
# 如果有冲突,解决后git rebase –continue
git push --force

此时,PR里别人的commit已经不见了,只有自己的