person github
If your new Pull Request (PR) contains changes from the previous PR, that's usually because you're creating the new branch not from the master branch main
(or other master branch), but from the branch containing the changes from the previous PR. In order to remove the changes from the previous PR in the new PR, you have several options:
Method 1: Create a new branch from the master branch
-
Switch to the master branch and update it:
git checkout main git pull origin main
-
Create a new branch from the master branch:
git checkout -b new-clean-feature-branch
-
Manually apply the changes you need to this new branch, then commit and push:
git add . git commit -m "Your commit message" git push origin new-clean-feature-branch
-
Create a new PR on GitHub using this new branch.
Method 2: Usegit rebase
If you're familiar with it git rebase
, you can try using it to remove unwanted commits.
-
Switch to your new branch:
git checkout new-feature-branch
-
Use
git rebase
interactive rebase:git rebase -i main
This will open a text editor listing all commits
main
beyond the branch. -
In a text editor, delete the commit lines that you don't want to be included in this new PR. Save and close the editor.
-
Complete rebase:
git rebase --continue
-
Force push changes to the remote branch:
git push origin new-feature-branch --force-with-lease
-
Now your PR should only contain the changes you want.
Be aware that git rebase
this is a powerful but dangerous tool, especially when you use it on a branch that is shared with others. Make sure you know what you are doing, especially when using --force-with-lease
the option to force push.
Hope this helps you! Have other questions?