Git-将指定文件回退到指定版本

场景1:修改了文件/path/to/file,没有提交,但是觉得改的不好,想还原。
解决
git checkout -- /path/to/file

场景2:修改了文件/path/to/file,已经提交,但是觉得改的不好,想还原到上衣版本。
解决

  1. 首先查看文件的历史版本。git log /path/to/file
  2. 找到你想要还原的版本。如
    commit 052c0233bcaef35bbf6e6ebd43bfd6a648e3d93b
    Author: panww
    Date: Wed Nov 8 11:48:31 2017 +0800
    commit modify/path/to/file
  3. 将文件还原到你想要还原的版本。$ git checkout ${commit} /path/to/file。即$ git checkout 052c0233bcaef35bbf6e6ebd43bfd6a648e3d93b /path/to/file
  4. 这时查看文件,会发现文件已经还原了。(如果没有还原,请刷新再看。)
  5. commit、push

ps
网上看到可以通过$ git reset ${commit} /path/to/file来还原。在Windows下使用Git Bash工具亲测不可用。

你可能感兴趣的:(精进基石,git)