LoginSignup
25
25

More than 5 years have passed since last update.

SVNからGitに移行した後にやること

Last updated at Posted at 2014-01-19

はじめに


SVNからの移行はこちら(SVNからgitへの移行)で書かれていますので詳細は任せるとして、
ここでは無事Gitに移行した後にやるべきことをメモっておきます。

ファイルの日付問題


SVNからGitに移行すると、
ファイルの日付が "git svn した日付" になってしまいます。
ファイルの更新日付を見ることでパッと見いつコミットしたか分かるのが良かったのですが、
これが全て同じ日付になってしまうと今までの苦労が無かったことに。。。
…とはならないですけど、気分的に少し嫌なものがあります。

どうするか


こういうときに便利なのが、
ここ(Gitのサンプルスクリプト)のgit-set-file-timesというスクリプトです。
これをローカルのクローンを置いているパスにコピーして来て実行してやると
ファイルの更新日付を綺麗にコミットした日付に置き換えてくれます。

MacなどのUNIX系の場合


Macなどはこれをコピーして使って下さい。

git-set-file-times.pl
#!/usr/bin/perl -w
use strict;

# sets mtime and atime of files to the latest commit time in git
#
# This is useful for serving static content (managed by git)
# from a cluster of identically configured HTTP servers.  HTTP
# clients and content delivery networks can get consistent
# Last-Modified headers no matter which HTTP server in the
# cluster they hit.  This should improve caching behavior.
#
# This does not take into account merges, but if you're updating
# every machine in the cluster from the same commit (A) to the
# same commit (B), the mtimes will be _consistent_ across all
# machines if not necessarily accurate.
#
# THIS IS NOT INTENDED TO OPTIMIZE BUILD SYSTEMS SUCH AS 'make'
# YOU HAVE BEEN WARNED!

my %ls = ();
my $commit_time;

if ($ENV{GIT_DIR}) {
    chdir($ENV{GIT_DIR}) or die $!;
}

$/ = "\0";
open FH, 'git ls-files -z|' or die $!;
while (<FH>) {
    chomp;
    $ls{$_} = $_;
}
close FH;


$/ = "\n";
open FH, "git log -m -r --name-only --no-color --pretty=raw -z @ARGV |" or die $!;
while (<FH>) {
    chomp;
    if (/^committer .*? (\d+) (?:[\-\+]\d+)$/) {
        $commit_time = $1;
    } elsif (s/\0\0commit [a-f0-9]{40}( \(from [a-f0-9]{40}\))?$// or s/\0$//) {
        my @files = delete @ls{split(/\0/, $_)};
        @files = grep { defined $_ } @files;
        next unless @files;
        utime $commit_time, $commit_time, @files;
    }
    last unless %ls;

}
close FH;

Windowsの場合


SIer的な環境は大体Windowsでやってたりしますので、
実際にやってみたときにPerlがなくて躓いたのでここに残す事にします。

まず、これがないと始まらないのでActivePerlをインストールします。
基本的にスクリプトは同じですが、1行目のシバン(またはシェバン) (shebang) を変更します。
パスはPerlのインストール先に合わせて下さい。

ActivePerlのインストール時に拡張子を関連付けていれば、ダブルクリックするだけなので簡単です。
一瞬で終わるので本当に変更されているのか不思議な感じです。

git-set-file-times.pl
#!C:¥Perl64¥bin¥perl -w
use strict;

# sets mtime and atime of files to the latest commit time in git
#
# This is useful for serving static content (managed by git)
# from a cluster of identically configured HTTP servers.  HTTP
# clients and content delivery networks can get consistent
# Last-Modified headers no matter which HTTP server in the
# cluster they hit.  This should improve caching behavior.
#
# This does not take into account merges, but if you're updating
# every machine in the cluster from the same commit (A) to the
# same commit (B), the mtimes will be _consistent_ across all
# machines if not necessarily accurate.
#
# THIS IS NOT INTENDED TO OPTIMIZE BUILD SYSTEMS SUCH AS 'make'
# YOU HAVE BEEN WARNED!

my %ls = ();
my $commit_time;

if ($ENV{GIT_DIR}) {
    chdir($ENV{GIT_DIR}) or die $!;
}

$/ = "\0";
open FH, 'git ls-files -z|' or die $!;
while (<FH>) {
    chomp;
    $ls{$_} = $_;
}
close FH;


$/ = "\n";
open FH, "git log -m -r --name-only --no-color --pretty=raw -z @ARGV |" or die $!;
while (<FH>) {
    chomp;
    if (/^committer .*? (\d+) (?:[\-\+]\d+)$/) {
        $commit_time = $1;
    } elsif (s/\0\0commit [a-f0-9]{40}( \(from [a-f0-9]{40}\))?$// or s/\0$//) {
        my @files = delete @ls{split(/\0/, $_)};
        @files = grep { defined $_ } @files;
        next unless @files;
        utime $commit_time, $commit_time, @files;
    }
    last unless %ls;

}
close FH;

おわりに


SVNだと1箇所にチーム全員がコミットするので、
コミット間違いやコミット漏れが時々発生します。
これが結構ストレスになったりもします。

Gitの場合はローカルでガンガンコミット出来て、ログも残せるのでとても便利です。
最初は学習コストがありますが、使い出すと面白いのでやってみる価値はあります。

こういうバージョン管理と合わせてCIツールを使うともっと開発が楽しくなりますね。

25
25
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
25