How can I reset or revert a file to a specific revision?

前端 未结 30 2017
不思量自难忘°
不思量自难忘° 2020-11-21 11:23

I have made some changes to a file which 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 versio

30条回答
  •  旧时难觅i
    2020-11-21 11:54

    As of git v2.23.0 there's a new git restore method which is supposed to assume part of what git checkout was responsible for (even the accepted answer mentions that git checkout is quite confusing). See highlights of changes on github blog.

    The default behaviour of this command is to restore the state of a working tree with the content coming from the source parameter (which in your case will be a commit hash).

    So based on Greg Hewgill's answer (assuming the commit hash is c5f567) the command would look like this:

    git restore --source=c5f567 file1/to/restore file2/to/restore
    

    Or if you want to restore to the content of one commit before c5f567:

    git restore --source=c5f567~1 file1/to/restore file2/to/restore
    

提交回复
热议问题