"Go" git delete commit

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.