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

前端 未结 30 1929
不思量自难忘°
不思量自难忘° 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:52

    Many suggestions here, most along the lines of git checkout $revision -- $file. A couple of obscure alternatives:

    git show $revision:$file > $file
    

    And also, I use this a lot just to see a particular version temporarily:

    git show $revision:$file
    

    or

    git show $revision:$file | vim -R -
    

    (OBS: $file needs to be prefixed with ./ if it is a relative path for git show $revision:$file to work)

    And the even more weird:

    git archive $revision $file | tar -x0 > $file
    

提交回复
热议问题