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

前端 未结 30 2014
不思量自难忘°
不思量自难忘° 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条回答
  •  自闭症患者
    2020-11-21 11:59

    In the case that you want to revert a file to a previous commit (and the file you want to revert already committed) you can use

    git checkout HEAD^1 path/to/file
    

    or

    git checkout HEAD~1 path/to/file
    

    Then just stage and commit the "new" version.

    Armed with the knowledge that a commit can have two parents in the case of a merge, you should know that HEAD^1 is the first parent and HEAD~1 is the second parent.

    Either will work if there is only one parent in the tree.

提交回复
热议问题