簡體   English   中英

如何在Git中查看文件歷史記錄?

[英]How to view file history in Git?

使用Subversion,我可以使用TortoiseSVN來查看文件的歷史記錄/日志。

我怎么能用Git做到這一點?

只查找特定文件的歷史記錄,然后比較不同版本的能力。

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

如果您想了解提交提交時發生的所有差異,請使用git loggit 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

看起來你想要git diff和/或git log 還可以看看gitk

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

我喜歡使用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

git-diff還是git-log

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM