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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1786027/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 07:23:47  来源:igfitidea点击:

How to view file history in Git?

gittimelinegit-diffgit-logrevision-history

提问by mrblah

With Subversion I could use TortoiseSVN to view the history/log of a file.

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

How can I do this with Git?

我怎样才能用 Git 做到这一点?

Just looking for history record for a particular file, and then the ability to compare the different versions.

只需查找特定文件的历史记录,然后就可以比较不同版本。

回答by Christian

Use git logto view the commit history. Each commit has an associated revision specifier that is a hash key (e.g. 14b8d0982044b0c49f7a855e396206ee65c0e787and b410ad4619d296f9d37f0db3d0ff5b9066838b39). To view the difference between two different commits, use git diffwith the first few characters of the revision specifiers of both commits, like so:

使用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

If you want to get an overview over all the differences that happened from commit to commit, use git logor git whatchangedwith the patch option:

如果您想大致了解一次提交之间发生的所有差异,请使用git loggit 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

回答by baudtack

Looks like you want git diffand/or git log. Also check out gitk

看起来你想要git diff和/或git log。还检查了gitk

gitk path/to/file
git diff path/to/file
git log path/to/file

回答by Gustavo Litovsky

I like to use gitk name_of_file

我喜欢用gitk name_of_file

This shows a nice list of the changes that happened to a file at each commit, instead of showing the changes to all the files. Makes it easier to track down something that happened.

这显示了每次提交时文件发生的更改的漂亮列表,而不是显示对所有文件的更改。更容易追踪发生的事情。

回答by user217433

you could also use tigfor a nice, ncurses-based git repository browser. To view history of a file:

您还可以将tig用于一个不错的、基于 ncurses 的 git 存储库浏览器。要查看文件的历史记录:

tig path/to/file

回答by chopper

My favorite is git log -p <filename>, which will give you a history of all the commits of the given file as well as the diffs for each commit.

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

回答by Jakub Nar?bski

Many Git history browsers, including git log(and 'git log --graph'), gitk (in Tcl/Tk, part of Git), QGit (in Qt), tig (text mode interface to git, using ncurses), Giggle (in GTK+), TortoiseGit and git-cheetah support path limiting (e.g. gitk path/to/file).

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

回答by J?rg W Mittag

Of course, if you want something as close to TortoiseSVN as possible, you could just use TortoiseGit.

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

回答by Edson Medina

git log --all -- path/to/fileshould work

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

回答by brianc

TortoiseGit also provides a command line toolto do see the history of a file. Using PowerShell:

TortoiseGit 还提供了一个命令行工具来查看文件的历史记录。使用 PowerShell:

C:\Program` Files\TortoiseGit\bin\TortoiseGitProc.exe /command:log /path:"c:\path\to\your\file.txt"

回答by vladikoff