To revert a single file to a previous version in Git, you can use the following command:
1. Revert to a specific commit’s version:
git checkout
Replace
Replace path/to/your/file with the relative path to the file you want to revert.
Example:
git checkout abc1234 — src/main.py
This will restore main.py to the state it was in at commit abc1234, but it will not modify the commit history or affect other files.
2. After Checkout:
If you want to keep this change, you can stage and commit it:
git add path/to/your/file
git commit -m “Revert file to previous version”
This will commit the file’s reverted state to the repository.