如何从Git中的特定修订版本检索单个文件?

空扰寡人 提交于 2020-08-08 14:29:31

问题:

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, and it's 27cf8e84bb88e24ae4b4b3df2b77aab91a3735d8 . 我在那个日期找到了修订版本,它是27cf8e84bb88e24ae4b4b3df2b77aab91a3735d8 I need to see what did one file looks like and also save that to a 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/如何从Git中的特定修订版本检索单个文件
参考二: https://oldbug.net/q/2Yk4/How-to-retrieve-a-single-file-from-a-specific-revision-in-Git
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!