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

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

    For me none of the reply seemed really clear and therefore I would like to add mine which seems super easy.

    I have a commit abc1 and after it I have done several (or one modification) to a file file.txt.

    Now say that I messed up something in the file file.txt and I want to go back to a previous commit abc1.

    1.git checkout file.txt : this will remove local changes, if you don't need them

    2.git checkout abc1 file.txt : this will bring your file to your wanted version

    3.git commit -m "Restored file.txt to version abc1" : this will commit your reversion.

    1. git push : this will push everything on the remote repository

    Between the step 2 and 3 of course you can do git status to understand what is going on. Usually you should see the file.txt already added and that is why there is no need of a git add.

提交回复
热议问题