Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (29.3k points)

I have made some changes to a file that has been committed a few times as part of a group of files, but now want to reset/revert the changes on it back to a previous version.

I have done a git log along with a git diff to find the revision I need, but just have no idea how to get the file back to its former state in the past

1 Answer

0 votes
by (50.2k points)

To reset or revert a specific file to a specific revision follow the command 

First, you need to have the hash of the commit then run this command

$ git checkout <hash-of-the-commit> -- file1/to/restore file2/to/restore
(file1/to/restore file2/to/restore is the path to the file that to be revert or reset to the specific version.
There will be a little confusion with the command because we use this to change the branches and also we use it for detaching.

Browse Categories