View the change history of a file using Git versioning
How can I view the change history of an individual file in Git, complete details with what has changed?
I have got as far as:
git log -- [filename]
which shows me the commit history of the file, but how do I get at the content of each of the file changes?
I'm trying to make the transition from MS SourceSafe and that used to be a simple right-click
→ show history
.
For this I'd use:
gitk [filename]
or to follow filename past renames
gitk --follow [filename]
You can use
git log -p filename
to let git generate the patches for each log entry.
See
git help log
for more options - it can actually do a lot of nice things :) To get just the diff for a specific commit you can
git show HEAD
or any other revision by identifier. Or use
gitk
to browse the changes visually.
git log --follow -p -- file
This will show the entire history of the file (including history beyond renames and with diffs for each change).
In other words, if the file named bar
was once named foo
, then git log -p bar
(without the --follow
option) will only show the file's history up to the point where it was renamed -- it won't show the file's history when it was known as foo
. Using git log --follow -p bar
will show the file's entire history, including any changes to the file when it was known as foo
. The -p
option ensures that diffs are included for each change.
上一篇: 有没有一个CSS父母选择器?
下一篇: 使用Git版本控制查看文件的更改历史记录