How can I revert a modified file to its previous revision at a specific commit hash (which I determined via git log and git diff)?
If you have a file1/to/restore file2/to / Restore, then go to git checkout if you want the hash of the commit is c5f567.\n\nThe git checkout man page provides more information. If you want to revert to the commit before c5f567, append 1 (where 1 is the number of commits you would like to go back): file checkout .5491, file1/to/restore file2/to / Restore:\n\nAs a side note, I\’ve always been uncomfortable with this command, which is used for both normal things (changing between branches) and strange, destructive objects (discarding changes in the working directory). For the meaning of — (in the command), see In Git.\n\nThere is also a special git restore command to restore working copy files that have been modified. If you have re-upgraded your gi, you can use this command, but the documentation is warning: .\n\nTHIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.\n\nSince git restore is experimental, it should not yet be promoted as the primary answer to this question. When the command is no longer marked as \”experimental\”, this answer can be amended to encourage the use of gi restore. [At the time of writing, the tit restore command has been marked with an experiment for at least four years.