To go back to a specific commit, you can use the git checkout
command followed by the commit hash. The commit hash is a unique identifier for each commit. You can find it by looking at your commit history with git log
.
Here’s how you can do it:
- First, view the commit history:
git log
This will show a list of all commits, each with its own commit hash, author, date, and commit message.
- Find the commit hash of the commit you want to go back to. It will look something like
3a0b9e9b381cf4a3f5e4add520bc9f0056b7c8b1
. - Check out that commit
git checkout <commit-hash>
Replace <commit-hash>
with the actual commit hash you found in step 2.
Please note that this will put your repository in a “detached HEAD” state, which means you’re not on any branch. If you want to make changes and keep them, you should create a new branch while you’re at it:
git checkout -b <new-branch-name> <commit-hash>
Replace <new-branch-name>
with the name you want to give to the new branch.