One time in the work accidentally submitted the code should not be submitted to git, and before the discovery of a few commits, and now want to permanently delete this commit on the GIT server, the specific steps are recorded as follows.
Assuming that the current branch is master, the current commit situation is as follows, and now you need to delete commit_id_2 and commit_id_4:
Commit_id_1commit_id_2commit_id_3commit_id_4commit_id_5 ....
First, create a new branch for the reset operation
git checkout-b developgit push orign-u Develop
Second, on the new branch develop, the commit is reset to commit_id_4 before the commit
git reset--hard <commit_id_5>
Third, submit a new branch, overwrite the previous commit information
git push orign HEAD--force
Iv. recover commits that do not need to be deleted, and then submit them in the original order
git cherry-pick commit_id_3git cherry-pick commit_id_1git push orign Develop
Delete the original master branch and checkout a new branch from the develop as master
git push orign--delete master//or git push orign:master//Note: Master is generally the default branch, you need to set the default branch to develop before you can delete git checkout-b maste Rgit Push orign-u master//finally reset master to the default branch
Operation is more cumbersome, but more insurance, if there is any good way, you can share a bit.
Reference:
Delete commits from a branch in Git
Move the most recent commit (s) to a new branch with Git
"Go" git delete commit