Rewind to a Specific Commit
As a developer, you may need to undo changes made to your codebase. For example, you may have made a mistake and need to go back to an earlier version of your code. In this challenge, you will use Git to rewind back to a specific commit in a repository.
To complete this lab, you will use the Git repository git-playground
from https://github.com/labex-labs/git-playground.git
. Follow these steps to complete the challenge:
- Clone the repository to your local machine:
git clone https://github.com/labex-labs/git-playground.git
- Navigate to the repository:
cd git-playground
- View the commit history of the repository:
git log --oneline
- Make sure that the commit message you want to rewind to is the "Initial commit" commit hash.
- Use the command
git reset <commit>
to rewind back to the specified commit. For example, you want to rewind back to the commit with hash 3050fc0d3
:
git reset 3050fc0d3
- View the commit history of the repository again:
git log --oneline
- If you want to delete the changes and revert to the earlier version of your code, use the command
git reset --hard <commit>
. For example, you want to delete the changes and revert to the commit with hash c0d30f305
:
git reset --hard c0d30f305
This is the result of running git log --oneline
:
c0d30f305 (HEAD -> master) Initial commit