如何從 Git 中的特定修訂版檢索單個檔案? - How to retrieve a single file from a specific revision in Git?

語言: CN / TW / HK

問題:

I have a Git repository and I'd like to see how some files looked a few months ago.我有一個 Git 儲存庫,我想看看幾個月前一些檔案的樣子。 I found the revision at that date;我在那個日期找到了修訂版; it's 27cf8e84bb88e24ae4b4b3df2b77aab91a3735d8 .它是27cf8e84bb88e24ae4b4b3df2b77aab91a3735d8 I need to see what one file looks like, and also save it as a ("new") file.我需要檢視一個檔案的外觀,並將其另存為(“新”)檔案。

I managed to see the file using gitk , but it doesn't have an option to save it.我設法使用gitk看到了該檔案,但它沒有儲存它的選項。 I tried with command-line tools, the closest I got was:我嘗試使用命令列工具,最接近的是:

git-show 27cf8e84bb88e24ae4b4b3df2b77aab91a3735d8 my_file.txt

However, this command shows a diff, and not the file contents.但是,此命令顯示差異,而不是檔案內容。 I know I can later use something like PAGER=cat and redirect output to a file, but I don't know how to get to the actual file content.我知道我以後可以使用PAGER=cat類的東西並將輸出重定向到檔案,但我不知道如何獲取實際的檔案內容。

Basically, I'm looking for something like svn cat .基本上,我正在尋找類似svn cat 的東西。


解決方案:

參考一: https://stackoom.com/question/2Yk4
參考二: How to retrieve a single file from a specific revision in Git?
「其他文章」