如何在Git中查看文件历史记录?

mrb*_*lah 125 git timeline git-diff git-log revision-history

使用Subversion,我可以使用TortoiseSVN来查看文件的历史记录/日志.

我怎么能用Git做到这一点?

只查找特定文件的历史记录,然后比较不同版本的能力.

Chr*_*ian 148

使用git log查看提交历史.每个提交都有一个关联的修订说明符,它是一个哈希键(例如14b8d0982044b0c49f7a855e396206ee65c0e787b410ad4619d296f9d37f0db3d0ff5b9066838b39).要查看两个不同提交之间的差异,请使用两个提交git diff的修订说明符的前几个字符,如下所示:

# diff between commits 14b8... and b410...
git diff 14b8..b410
# only include diff of specified files
git diff 14b8..b410 path/to/file/a path/to/file/b
Run Code Online (Sandbox Code Playgroud)

如果要概述提交提交时发生的所有差异,请使用git loggit whatchanged使用patch选项:

# include patch displays in the commit history
git log -p
git whatchanged -p
# only get history of those commits that touch specified paths
git log path/a path/b
git whatchanged path/c path/d
Run Code Online (Sandbox Code Playgroud)

  • 感谢-p提示,这对于查找哪些修订涉及一些代码非常有用. (7认同)

bau*_*ack 93

看起来你想要git diff和/或git log.还可以看看gitk

gitk path/to/file
git diff path/to/file
git log path/to/file
Run Code Online (Sandbox Code Playgroud)

  • 这是gitk的另一个点头,它提供了一种浏览git仓库中单个文件的所有快照的好方法. (3认同)

Gus*_*sky 34

我喜欢使用gitk name_of_file

这显示了每次提交时文件发生的更改的清单,而不是显示所有文件的更改.可以更轻松地追踪发生的事情.


小智 30

你也可以使用tig作为一个很好的,基于ncurses的git存储库浏览器.要查看文件的历史记录:

tig path/to/file
Run Code Online (Sandbox Code Playgroud)


cho*_*per 25

我最喜欢的是git log -p <filename>,它将为您提供给定文件的所有提交的历史记录以及每个提交的差异.


Jak*_*ski 11

许多Git历史浏览器,包括git log(和'git log --graph'),gitk(在Tcl/Tk中,在Git中的一部分),QGit(在Qt中),tig(到git的文本模式接口,使用ncurses),Giggle(在GTK +),TortoiseGit和git-cheetah支持路径限制(例如gitk path/to/file).


Eds*_*ina 6

git log --all -- path/to/file应该管用

  • 这应该是最重要的答案。我不喜欢使用蹩脚的 GUI 工具 (3认同)

Jör*_*tag 5

当然,如果你想要尽可能接近TortoiseSVN,你可以使用TortoiseGit.