Restore file from old commit in git

前端 未结 4 1821
悲哀的现实
悲哀的现实 2020-12-02 04:18

I have an old commit that I did a few weeks ago. I want to restore only a single file from that commit. What do I do?

4条回答
  •  一生所求
    2020-12-02 05:10

    git checkout 'master@{7 days ago}' -- path/to/file.txt
    

    This will not alter HEAD, it will just overwrite the local file path/to/file.txt

    See man git-rev-parse for possible revision specifications there (of course a simple hash (like dd9bacb) will do nicely)

    Don't forget to commit the change (after a review...)

提交回复
热议问题