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 <panww@gmail.com>
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工具親測不可用。

 

轉自:https://blog.csdn.net/panweiwei1994/article/details/78501371


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM