Remove the last commit from the remote git repository
In this short article, show you how to remove the last commit from the git repository.
Checkout more articles on Git
- Undo commit before push in Git
- Delete all commit history in GitHub
- Configure git to ignore some files locally
- How to change the commit message in git
Here, we will see three simple steps to remove the last commit from the local and remote git repository.
Steps to remove the last commit from the remote git repository
1. Check the logs
First of all, check your local commit with messages before removing the last commit. Run the following command to check the logs in one line.
git log --oneline
2. Remove the last commit from the local branch
Now, Run the following command to remove the last commit and discard the changes from the local branch.
git reset --hard HEAD~1
Checkout the different ways to Undo commit before push in Git.
3. Update remote repository
At last, we will update the files and again need to push with force. It will delete the previous commit and keep a new one on the remote git repository.
git push origin <name_of_branch> -f
</name_of_branch>
Now you can check the logs to verify the commit in the git repository.
I hope you find this article helpful.
Thank you for reading. Happy Coding..!! π