git logでソースのdiffを見る
何回も調べなおしているのでブログに残しておきます。
- git diffはcommit同士を比較できるけどなんか直感的じゃない。(いちいちcommit hashを調べる必要がある)
- 直近のcommitでカジュアルにlogにソースコードの差分まで載せて表示するには
-p
オプションが使えるようだ。
git log -p [<filename>]
file名は任意。つけないと履歴に含まれる全ファイルの差分が表示される
このオプションはhelpに表示されていないがpro gitには書かれている
$ git log -h usage: git log [<options>] [<revision-range>] [[--] <path>...] or: git show [<options>] <object>... -q, --quiet suppress diff output --source show source --use-mailmap Use mail map file --decorate-refs <pattern> only decorate refs that match <pattern> --decorate-refs-exclude <pattern> do not decorate refs that match <pattern> --decorate[=...] decorate options -L <n,m:file> Process line range n,m in file, counting from 1
もっとも便利なオプションのひとつが -p で、これは各コミットの diff を表示します。また -2 は、直近の 2 エントリだけを出力します。
$ git log -p -2 commit ca82a6dff817ec66f44342007202690a93763949 Author: Scott Chacon <schacon@gee-mail.com> Date: Mon Mar 17 21:52:11 2008 -0700 changed the version number diff --git a/Rakefile b/Rakefile index a874b73..8f94139 100644 --- a/Rakefile +++ b/Rakefile @@ -5,5 +5,5 @@ require 'rake/gempackagetask' spec = Gem::Specification.new do |s| s.name = "simplegit" - s.version = "0.1.0" + s.version = "0.1.1" s.author = "Scott Chacon" s.email = "schacon@gee-mail.com commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 Author: Scott Chacon <schacon@gee-mail.com> Date: Sat Mar 15 16:40:33 2008 -0700 removed unnecessary test code diff --git a/lib/simplegit.rb b/lib/simplegit.rb index a0a60ae..47c6340 100644 --- a/lib/simplegit.rb +++ b/lib/simplegit.rb @@ -18,8 +18,3 @@ class SimpleGit end end - -if $0 == __FILE__ - git = SimpleGit.new - puts git.show -end \ No newline at end of file
こういうチップスをたくさんサブブログにためてメインブログにマージした記事を書くかもしれない。