Revert a check-in file in Git
To revert a file to a previous version in Git, follow these steps:
- View the commit history for the file: Use
git log
followed by the file name to see the commit history for that specific file:
git log --oneline <filename>
This will display a concise list of commits that have modified the file.
2. Checkout the previous version of the file: Use the git checkout
command followed by the commit hash and the file name:
git checkout <commit_hash> -- <filename>
Replace <commit_hash>
with the hash of the commit that contains the version of the file you want to revert to.
3. Commit the change: To save the reverted file, commit the change:
git add <filename>
git commit -m "Reverted changes to <filename>"
4. Push the changes: Finally, push the updated branch to the remote repository:
git push origin <branch_name>
Happy Coding 🙂