Rewind Commits
As a developer, you have been working on a project and have made several commits. However, you realize that the last few commits contain errors and you need to go back to a previous version of your code. You need to use Git to rewind your commits and get back to the previous version of your code.
To complete this lab, you will use the Git repository git-playground
from your GitHub account, which comes from a fork of https://github.com/labex-labs/git-playground.git
. Follow these steps:
- Clone the repository to your local machine:
git clone https://github.com/your-username/git-playground.git
cd git-playground
- Create a new branch called
rewind-commits
:
git checkout -b rewind-commits
- View the commit history of the repository and realize that the last commit contain errors and you need to go back to the previous version of your code:
git log
- Use Git to rewind your commits by 1:
git reset HEAD~1 --hard
- Verify that you have successfully rewound your commits:
git log
- Push your changes to the
rewind-commits
branch:
git push --force origin rewind-commits
This is the final result:
cf80005 (HEAD -> rewind-commits, origin/rewind-commits) Added file1.txt
b00b937 Initial commit