はじめに
git コマンドで clone すると、タイムスタンプが clone した時点の日付になると思う。
それでは、make コマンドを使う時など、タイムスタンプがずれていると困ることがある。
そのような時のためのメモ。
git のタイムスタンプには author date と committer date の2つがあります。
commiter date は rebase など際にも書き換わることがあるようなので、基本は author date に変換します。
リポジトリ管理されているファイルの一覧を取得
git ls-files
指定ファイルの日付を取得
前述の通り author date を取得します。
あとで touch
に渡したいので、それで扱える形式で出力します。
git log -1 --date=format-local:"%Y%m%d%H%M%S" --pretty=format:"%ad" "${file}"
-
-1
は最新 1 コミット分の出力 -
--date=format-local:
は、ユーザーのローカルタイムゾーン、かつ指定フォーマットで出力する -
--pretty=format:
は、出力項目を指定(%ad で author date)
指定ファイルの日付を変更する
touch -t "${timestamp}" "${file}"
-
-t
に渡すのはローカルタイムの値
まとめると
git-retouch
#!/bin/sh
for file in $(git ls-files); do
timestamp=$(git log -1 --date=format-local:"%Y%m%d%H%M%S" --pretty=format:"%ad" "${file}")
touch -t "${timestamp}" "${file}"
done