In this tutorial, we are going to learn about how to undo the git repository to a previous commit.
If your commit is not pushed to a remote git repository and you are trying to revert it to a previous commit follow the below steps.
- Inside the command line navigate to a repository, you want to undo it back to a previous commit.
- Run the
git revertcommand followed by the
git revert HEAD
This above command will create a new commit based on the previous commit, it doesn’t change any previous commit history.
Headis referencing to a last commit in the current branch
If your commit is pushed to a remote git repository and you are trying to revert it to a previous commit.
- Follow the above two steps
- Now, push your repository to remote by running the
git pushcommand followed by the
git push -f