使用git log
查看提交历史记录。每个提交都有一个关联的修订指定符,它是一个哈希键(例如14b8d0982044b0c49f7a855e396206ee65c0e787
和b410ad4619d296f9d37f0db3d0ff5b9066838b39
)。要查看两个不同提交之间的差异,请使用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
如果你想了解每个提交之间发生的所有差异,请使用git log
或带有补丁选项的git whatchanged
。
# 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
我最喜欢的是git log -p <文件名>
,它可以为您提供给定文件的所有提交历史记录以及每个提交的差异。
我喜欢使用 gitk 文件名
这将显示文件在每次提交时发生的变化的一个很好的列表,而不是显示所有文件的更改情况。这样可以更轻松地追踪发生的事件。
许多 Git 历史记录浏览器,包括 git log
(和 'git log --graph')、gitk(在 Git 中的 Tcl/Tk 中)、QGit(在 Qt 中)、tig(使用 ncurses 的文本模式接口到 Git)、Giggle(在 GTK+中)、TortoiseGit 和 git-cheetah 都支持路径限制(例如:gitk path/to/file
)。
git log --all -- path/to/file
应该可以工作。
TortoiseGit同样提供了一个命令行工具来查看文件的历史记录。使用PowerShell:
C:\Program` Files\TortoiseGit\bin\TortoiseGitProc.exe /command:log /path:"c:\path\to\your\file.txt"