how to delete last 3 commit and push to remote
To delete the last 3 commits and push the changes to the remote repository, you can follow these steps:
-
Open your terminal or command prompt.
-
Navigate to the local repository directory where you have cloned the repository.
-
Ensure that you are currently on the branch from which you want to delete the commits.
-
Use the following command to view the commit history and identify the commits you want to remove:
git logNote down the commit hashes or messages of the last 3 commits you want to delete.
-
Run the following command to delete the last 3 commits:
git reset --hard HEAD~3This command will remove the last 3 commits and reset the branch pointer to the commit before them. Be cautious as this is an irreversible action.
-
After deleting the commits, push the changes to the remote repository using the following command:
git push --force origin <branch-name>Replace
<branch-name>with the actual name of your branch.Note: The
--forceflag is required because you are rewriting the commit history, and Git will reject a normal push to prevent data loss. Be careful when using the--forceflag as it can cause problems for others collaborating on the repository.
After following these steps, your last 3 commits will be removed from the branch and the changes will be pushed to the remote repository
原文地址: https://www.cveoy.top/t/topic/iooT 著作权归作者所有。请勿转载和采集!