特定コミットの情報を表示させるにはgit showコマンドを使うと思いますが、その中からコミット時刻だけを取りたいというような場合。
例えばHEADの情報を表示させるには
git show HEAD
で
commit d520594c8750b0531344415ec3d3f66b9ba1d7f5
Author: dameninngenn <dameninngenn.owata@gmail.com>
Date: Sat Dec 31 18:09:38 2011 +0900
unite-scripts/nicoranking.pl
diff --git a/.vimrc b/.vimrc
index 255a5d1..15733e1 100644
--- a/.vimrc
+++ b/.vimrc
@@ -347,6 +347,9 @@ nnoremap <silent> <Leader>up :<C-u>Unite phrase<CR>
vnoremap <silent> <Leader>1 :BlockDiff1<CR>
vnoremap <silent> <Leader>2 :BlockDiff2<CR>
+" Unite用スクリプト
+nnoremap <silent> <Leader>un :Unite script:perl:~/.vim/unite-scripts/nicoranking.pl<CR>
+
" http://subtech.g.hatena.ne.jp/motemen/20110817/1313577108
nnoremap <buffer> <silent> ( :<C-U>call PreviewOpenBrace()<CR>
if !exists('*PreviewOpenBrace')
@@ -461,6 +464,7 @@ function! s:unite_source.gather_candidates(args, context)
\ { 'word': ',r 【スクリプト実行】[quickrun]', 'source': 'my_help', 'kind': 'word' },
\ { 'word': ',yr 【yankリスト表示】[yankring]', 'source': 'my_help', 'kind': 'word' },
\ { 'word': ',1/,2 【選択範囲のdiff表示】[blockdiff]', 'source': 'my_help', 'kind': 'word' },
+ \ { 'word': ',un 【ニコニコ動画のランキング表示】[unite-scripts]', 'source': 'my_help', 'kind': 'word' },
\ { 'word': '( 【今いるスコープの括弧を表示】[user]', 'source': 'my_help', 'kind': 'word' },
\ { 'word': 'dit 【XMLタグに囲まれた範囲を削除】[system][xml]', 'source': 'my_help', 'kind': 'word' },
\ { 'word': ':GoogleTasks 【googletasksの内容を表示】[command][googletasks]', 'source': 'my_help', 'kind': 'word' },こんな感じで表示される。時刻はDate:の部分ですね。
ここで--pretty=formatのオプションで時刻だけ表示させようとすると、
git show --pretty=format:"%cd" HEAD
Sat Dec 31 18:09:38 2011 +0900
diff --git a/.vimrc b/.vimrc
index 255a5d1..15733e1 100644
--- a/.vimrc
+++ b/.vimrc
@@ -347,6 +347,9 @@ nnoremap <silent> <Leader>up :<C-u>Unite phrase<CR>
vnoremap <silent> <Leader>1 :BlockDiff1<CR>
vnoremap <silent> <Leader>2 :BlockDiff2<CR>
+" Unite用スクリプト
+nnoremap <silent> <Leader>un :Unite script:perl:~/.vim/unite-scripts/nicoranking.pl<CR>
+
" http://subtech.g.hatena.ne.jp/motemen/20110817/1313577108
nnoremap <buffer> <silent> ( :<C-U>call PreviewOpenBrace()<CR>
if !exists('*PreviewOpenBrace')
@@ -461,6 +464,7 @@ function! s:unite_source.gather_candidates(args, context)
\ { 'word': ',r 【スクリプト実行】[quickrun]', 'source': 'my_help', 'kind': 'word' },
\ { 'word': ',yr 【yankリスト表示】[yankring]', 'source': 'my_help', 'kind': 'word' },
\ { 'word': ',1/,2 【選択範囲のdiff表示】[blockdiff]', 'source': 'my_help', 'kind': 'word' },
+ \ { 'word': ',un 【ニコニコ動画のランキング表示】[unite-scripts]', 'source': 'my_help', 'kind': 'word' },
\ { 'word': '( 【今いるスコープの括弧を表示】[user]', 'source': 'my_help', 'kind': 'word' },
\ { 'word': 'dit 【XMLタグに囲まれた範囲を削除】[system][xml]', 'source': 'my_help', 'kind': 'word' },
\ { 'word': ':GoogleTasks 【googletasksの内容を表示】[command][googletasks]', 'source': 'my_help', 'kind': 'word' },となって上部のとこは時刻だけにまとまってますが、diffは表示されたままになります。
詳しくは調べてないですがgit showはlog部分とdiff部分で別々のものを組み合わせて表示してるという感じなのでしょうか。時刻だけ取りたいのに下のdiffの部分はいらないので--quietオプションで消します。
git show --quiet --pretty=format:"%cd" HEAD
これで
Sat Dec 31 18:09:38 2011 +0900
だけとってこれます。formatの%cdを%ctとかにするとepochでとれたりしますね。
HEADのかわりにタグ名とか特定コミットのSHA1とか指定すれば好きなとこの時刻がとってこれます。
git-logとかgit-showは指定できるオプション多すぎてよくわからない。。