Restore Changes to a File in Git
In case we need to undo changes to a file and return it to its original form, we need to use the restore
command. Let's first make changes to the file.txt
file and track its status:
git status
In the message we will see that the file file.txt
has received the status modified.
Now let's return the file to its original state using the restore
command:
git restore file.txt
After checking the status, we will see a message that there is nothing to commit. If you check the file content, it will indeed return to the version before the changes. You need to be careful with this command, because Git replaces the file with its previous version and all intermediate changes are erased.
Make changes to a file in your Git repository, then revert it to its original state.