如何使用Git查看文件的旧版本? [英] How can I view an old version of a file with Git?

查看:135
本文介绍了如何使用Git查看文件的旧版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Git中是否有命令来查看(转储到stdout或在$PAGER$EDITOR中)特定文件的特定版本?

Is there a command in Git to see (either dumped to stdout, or in $PAGER or $EDITOR) a particular version of a particular file?

推荐答案

您可以将git show与来自存储库根目录的路径(./../用于相对路径)一起使用:

You can use git show with a path from the root of the repository (./ or ../ for relative pathing):

$ git show REVISION:path/to/file

REVISION替换为您的实际修订版(可以是Git提交SHA,标签名称,分支名称,相对提交名称,或在Git中标识提交的任何其他方式)

Replace REVISION with your actual revision (could be a Git commit SHA, a tag name, a branch name, a relative commit name, or any other way of identifying a commit in Git)

例如,要查看4次提交之前文件<repository-root>/src/main.c的版本,请使用:

For example, to view the version of file <repository-root>/src/main.c from 4 commits ago, use:

$ git show HEAD~4:src/main.c

用于Windows的Git甚至在相对于当前目录的路径中也需要正斜杠.有关更多信息,请查看 git-show 的手册页.

Git for Windows requires forward slashes even in paths relative to the current directory. For more information, check out the man page for git-show.

这篇关于如何使用Git查看文件的旧版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆