git stash

Suppose there are three Commits as follows

commit 3
commit 2
commit 1
Copy the code

If you want to undo the last commit 3, do the following:

Git reset commitID // to the previous versionCopy the code
Git stash // Stash changes temporarilyCopy the code
Git push --force git push --force git pushCopy the code
Git Stash pop // Releases the saved changes and starts modifying the codeCopy the code
git add .
git commit -m "message"
git push
Copy the code

Pay attention to

If you just need to delete COMMIT 3, you can perform steps 1 and 3 directly

Git reset --hard commitID // --hard native code also goes back to commit 2Copy the code
git push --force
Copy the code

How does Git delete an incorrect commit from a remote repository?