Git:整个文件到stdout

Joe*_*oel 32 git

是否有一个命令可以接受ref和文件路径,并输出文件的全部内容,因为它是在STDOUT的提交时?

例如.像这样的东西:

git show-me-the-file HEAD~2 some/file | do_something_with_piped_output_here
Run Code Online (Sandbox Code Playgroud)

eqz*_*qzx 46

git show

例如

git show HEAD:./<path_to_file>

  • `| 不需要cat`(除非你想阻止寻呼机进入). (3认同)
  • ":" 很重要,否则您将看到差异而不是完整文件。 (2认同)

Op *_*kel 8

git show <ref spec>:<path> 例如,如果要在提交点9be20d1bf62查看文件,则执行以下操作:

git show 9be20d1bf62:a/b/file.txt

如果你想在特定分支上看到文件:

git show <branch name>:<path>