To revert a committed file to an earlier version using Git, you can use the git checkout
command. Here's how you can do it:
git checkout {{commit_hash}} -- {{file_path}}
Replace {{commit_hash}}
with the hash of the commit you want to revert to, and {{file_path}}
with the path to the file you want to revert.
For example, if you want to revert the file script.js
to an earlier version with the commit hash abc123
, you would run:
git checkout abc123 -- script.js
This command will replace the contents of script.js
with the version from the commit specified by abc123
.
Note that this operation will discard any uncommitted changes in the file, so make sure to commit or stash any changes you want to keep before running the git checkout
command.