How to remove the changes in the previous PR in the new PR?

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

  1. Switch to the master branch and update it:

    git checkout main
    git pull origin main
    
  2. Create a new branch from the master branch:

    git checkout -b new-clean-feature-branch
    
  3. 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
    
  4. 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.

  1. Switch to your new branch:

    git checkout new-feature-branch
    
  2. Use git rebaseinteractive rebase:

    git rebase -i main
    

    This will open a text editor listing all commits mainbeyond the branch.

  3. 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.

  4. Complete rebase:

    git rebase --continue
    
  5. Force push changes to the remote branch:

    git push origin new-feature-branch --force-with-lease
    
  6. Now your PR should only contain the changes you want.

Be aware that git rebasethis 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-leasethe option to force push.

Hope this helps you! Have other questions?

Guess you like

Origin blog.csdn.net/m0_57236802/article/details/132898646