[英]How to view file history in Git?
使用Subversion,我可以使用TortoiseSVN來查看文件的歷史記錄/日志。
我怎么能用Git做到這一點?
只查找特定文件的歷史記錄,然后比較不同版本的能力。
使用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
with 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
我喜歡使用gitk name_of_file
這顯示了每次提交時文件發生的更改的清單,而不是顯示所有文件的更改。 可以更輕松地追蹤發生的事情。
你也可以使用tig作為一個很好的,基於ncurses的git存儲庫瀏覽器。 要查看文件的歷史記錄:
tig path/to/file
我最喜歡的是git log -p <filename>
,它將為您提供給定文件的所有提交的歷史記錄以及每次提交的差異。
許多Git歷史瀏覽器,包括git log
(和'git log --graph'),gitk(在Tcl / Tk中,在Git中的一部分),QGit(在Qt中),tig(到git的文本模式接口,使用ncurses),Giggle (在GTK +中),TortoiseGit和git-cheetah支持路徑限制(例如gitk path/to/file
)。
當然,如果你想要盡可能接近TortoiseSVN,你可以使用TortoiseGit 。
TortoiseGit還提供了一個命令行工具來查看文件的歷史記錄。 使用PowerShell:
C:\Program` Files\TortoiseGit\bin\TortoiseGitProc.exe /command:log /path:"c:\path\to\your\file.txt"
git log --all -- path/to/file
應該有效
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.