xxxxxxxxxx
git push <remote_name> +<commit_sha>:<branch_name>
xxxxxxxxxx
If you want to delete for example the last 3 commits, run the following command to remove the changes from the file system (working tree) and commit history (index) on your local branch:
git reset --hard HEAD~3
Then run the following command (on your local machine) to force the remote branch to rewrite its history:
git push --force
xxxxxxxxxx
git reset --hard <last_working_commit_id>
So we must not reset to the commit_id that we don't want.
Then sure, we must push to remote branch:
git push --force
xxxxxxxxxx
# Step 1: Clone the remote repository
git clone <remote_repository_url>
# Step 2: Move into the cloned repository's directory
cd <repository_directory>
# Step 3: List all commits to identify the commit to be removed
git log
# Step 4: Remove the commit using its hash
git push origin +<commit_hash>^:<branch_name>