git-checkout二进制文件的旧版本,不会覆盖工作副本

时间:2016-02-11 22:04:33

标签: git

我的git存储库中有一个二进制文件(foo.bin)。

如何在不覆盖工作副本中的文件的情况下签出此文件的旧版本?

类似的东西:

git checkout tag-name -- foo.bin > foo-tag-name.bin

2 个答案:

答案 0 :(得分:4)

你的命令几乎是正确的:

git show tag-name:foo.bin > foo-tag-name.bin

git help 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.

git help gitrevisions

中描述了该语法
   <rev>:<path>, e.g. HEAD:README, :README, master:./README
       A suffix : followed by a path names the blob or tree at the given
       path in the tree-ish object named by the part before the colon.

答案 1 :(得分:1)

git show是您正在寻找的命令:

git show tag-name:foo.bin > foo-tag-name.bin