0%

[git] How to diff the same file between two different commits

這功能很有用,SVN的時代常常使用,不過在Git上就忘了怎麼用。
看到Stackoverflow的資料紀錄一下。

首先,先查詢某個檔案的Commit log。

1
$ git log -- [filename]

以下是一個示範

1
2
3
4
5
6
$ git log --pretty=oneline --abbrev-commit -- README.md
a442aa7 doc: small fixes to comments and syntax
acb9f89 doc: adding ARCHS flag to OS X build command
7d23c1d doc: add libuv-dox to the documentation section
2025341 doc: add readme link to all projects that use libuv.
8094ac2 doc: document how to run tests

接著就可以用git diff來比較兩個commit之間的差異。

1
$ git diff {version1} {version2} -- [filename]

如果我們要看README.md的前一個版本跟現在的版本差異,就能這樣操作

1
$ git diff acb9f89 HEAD -- README.md

有個好的GUI果然比較有用,這些技術以備不時之需。