How to remove your commits from submitted PR

When you submit a PR, it includes a wrong previous commit. How to remove these commits?

If you are developing on another branch, switch to that branch. If you are developing on main, you can skip this step.

git checkout your-branch

In Github,…


This content originally appeared on DEV Community and was authored by Junyu

When you submit a PR, it includes a wrong previous commit. How to remove these commits?

If you are developing on another branch, switch to that branch. If you are developing on main, you can skip this step.

git checkout your-branch

In Github, view the current PR and check how many commits it includes. Replace n in the following command with the number of commits and execute it (if you have synchronized the fork, there will be new commits in Github, but they will not be shown in VS Code, so the rebase result may be earlier than the first commit of the PR):

git rebase -i HEAD~n

In the command line, you will see something like the following text:

pick 888a17a add pnpm setting in windows (#15)
pick 472jkda add pnpm setting in windows
pick 472bd9c add switch butoon
pick 0369726 add dark theme change
……

The commit with the Github PR number will be shown with a hash symbol and the PR number. For example, if I want to remove the second commit, I will change pick to drop.

To force push the changes, use the following command:

git push origin HEAD:your-branch --force

This will force push the changes to Github, and the PR commits will be updated.


This content originally appeared on DEV Community and was authored by Junyu


Print Share Comment Cite Upload Translate Updates
APA

Junyu | Sciencx (2025-08-20T05:29:40+00:00) How to remove your commits from submitted PR. Retrieved from https://www.scien.cx/2025/08/20/how-to-remove-your-commits-from-submitted-pr/

MLA
" » How to remove your commits from submitted PR." Junyu | Sciencx - Wednesday August 20, 2025, https://www.scien.cx/2025/08/20/how-to-remove-your-commits-from-submitted-pr/
HARVARD
Junyu | Sciencx Wednesday August 20, 2025 » How to remove your commits from submitted PR., viewed ,<https://www.scien.cx/2025/08/20/how-to-remove-your-commits-from-submitted-pr/>
VANCOUVER
Junyu | Sciencx - » How to remove your commits from submitted PR. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/08/20/how-to-remove-your-commits-from-submitted-pr/
CHICAGO
" » How to remove your commits from submitted PR." Junyu | Sciencx - Accessed . https://www.scien.cx/2025/08/20/how-to-remove-your-commits-from-submitted-pr/
IEEE
" » How to remove your commits from submitted PR." Junyu | Sciencx [Online]. Available: https://www.scien.cx/2025/08/20/how-to-remove-your-commits-from-submitted-pr/. [Accessed: ]
rf:citation
» How to remove your commits from submitted PR | Junyu | Sciencx | https://www.scien.cx/2025/08/20/how-to-remove-your-commits-from-submitted-pr/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.