使用場(chǎng)景
某個(gè)文件曾在Gi倉(cāng)庫(kù)里的,某次提交commit時(shí)刪除了該文件,后來(lái)想要恢復(fù),怎么辦呢?
步驟
首先需要找到在哪個(gè)commit里該文件被刪除:
git rev-list -n 1 HEAD -- <file_path>
接著通過(guò)該commit id,恢復(fù)該文件
git checkout <deleting_commit>^ -- <file_path>
參考Stackoverflow的帖子
https://stackoverflow.com/questions/953481/find-and-restore-a-deleted-file-in-a-git-repository