To delete the last 3 commits and push the changes to the remote repository, you can follow these steps:

  1. Open your terminal or command prompt.

  2. Navigate to the local repository directory where you have cloned the repository.

  3. Ensure that you are currently on the branch from which you want to delete the commits.

  4. Use the following command to view the commit history and identify the commits you want to remove:

    git log
    

    Note down the commit hashes or messages of the last 3 commits you want to delete.

  5. Run the following command to delete the last 3 commits:

    git reset --hard HEAD~3
    

    This 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.

  6. 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 --force flag 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 --force flag 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 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录