取出 git commit 紀錄中的某一個檔案內容
指令
# 直接在終端機(Terminal)查看內容
git show <commit-id>:<path/to/file>
git show a1b2c3d:src/main.py
# 將該內容輸出並存成新檔案
git show <commit-id>:<path/to/file> > <output-filename>
git show a1b2c3d:src/main.py > main_old.py
#在新版 git 中也可以使用 restore 參數「直接還原」工作目錄中的該檔案
git restore --source=<commit-id> <path/to/file>
使用情境
取出 commit 紀錄中某一個檔案的內容, 可以人工比對確認內容或是回復到舊版, 例如:也許要回復到前 3~5 個版本的內容