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

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

    You can do it in 4 steps:

    1. revert the entire commit with the file you want to specifically revert - it will create a new commit on your branch
    2. soft reset that commit - removes the commit and moves the changes to the working area
    3. handpick the files to revert and commit them
    4. drop all other files in your work area

    What you need to type in your terminal:

    1. git revert
    2. git reset HEAD~1
    3. git add && git commit -m 'reverting file'
    4. git checkout .

    good luck

提交回复
热议问题