相当于"hg cat"或"svn cat"的git

Ric*_*ton 83 git version-control

我想提取一个git存储库中保存的文件的最新版本的副本,并将其传递给脚本进行一些处理.使用svn或hg,我只使用"cat"命令:

按指定的修订版打印指定的文件.如果没有给出修订,则使用工作目录的父级,如果没有签出修订,则提示.

(这是来自hg文档中hg cat的描述)

使用git执行此操作的等效命令是什么?

Tor*_*amo 110

git show rev:path/to/file
Run Code Online (Sandbox Code Playgroud)

转速是修订.

有关git和svn命令的比较,请参见http://git.or.cz/course/svn.html.


小智 9

有"git cat-file"你可以像这样运行:

$ git cat-file blob v1.0:path/to/file

你可以用你想要的分支,标记或提交SHA替换'v1.0',然后用存储库中的相对路径替换'path/to/file'.如果需要,您还可以传递'-s'以查看内容的大小.

可能更接近你习惯的'猫'命令,虽然前面提到的'show'会做同样的事情.


And*_*ett 5

git show是你要找的命令.从文档:

   git show next~10:Documentation/README
          Shows the contents of the file Documentation/README as they were
          current in the 10th last commit of the branch next.
Run Code Online (Sandbox Code Playgroud)

  • 你有一个名为“下一个”的分支吗?如果您想要当前分支,请改用“HEAD”。 (2认同)