場景1:修改了文件/path/to/file,沒有提交,但是覺得改的不好,想還原。
解決:
git checkout -- /path/to/file
場景2:修改了文件/path/to/file,已經提交,但是覺得改的不好,想還原到上衣版本。
解決:
- 首先查看文件的歷史版本。
git log /path/to/file
- 找到你想要還原的版本。如
commit 052c0233bcaef35bbf6e6ebd43bfd6a648e3d93b
Author: panww <panww@gmail.com>
Date: Wed Nov 8 11:48:31 2017 +0800
commit modify/path/to/file
- 將文件還原到你想要還原的版本。
$ git checkout ${commit} /path/to/file
。即$ git checkout 052c0233bcaef35bbf6e6ebd43bfd6a648e3d93b /path/to/file
- 這時查看文件,會發現文件已經還原了。(如果沒有還原,請刷新再看。)
commit、push
。
ps:
網上看到可以通過$ git reset ${commit} /path/to/file
來還原。在Windows下使用Git Bash工具親測不可用。