subversionメモ

CentOS5 ローカルでのsvn(subversion)メモ。以下を参照しながら。

http://www.hyuki.com/techinfo/svninit.html

リポジトリ作成、初期化

$ cd
$ pwd
/home/foo
$ mkdir SVN-repos
$ svnadmin create /home/foo/SVN-repos/

新規プロジェクトのインポート

work/myprojectとしてリポジトリにインポートする。コメントは"Inital import."。

$ cd public_html/work
$ mkdir myproject
$ cd myproject
$ cp -ip /home/foo/bar/*.html .
$ svn import file:///home/foo/SVN-repos/work/myproject -m "Initial import."
追加しています              index.html
追加しています              test.html

リビジョン 1 をコミットしました。
$

チェックアウトの確認

importしたファイルをディレクトリごとrenameしてcheckoutしてみる。

$ cd ..
$ mv myproject myproject.sv
$ svn checkout file:///home/foo/SVN-repos/work/myproject myproject
A    session/index.html
A    session/test.html
リビジョン 1 をチェックアウトしました。
$ ls -l
drwxr-xr-x 3 foo bargroup 4096  128 16:19 myproject
drwxr-xr-x 2 foo bargroup 4096  128 16:09 myproject.sv
$ cd myproject
$ ls -al
drwxr-xr-x 3 foo bargroup 4096  128 16:19 ./
drwxr-xr-x 4 foo bargroup 4096  128 16:19 ../
drwxr-xr-x 6 foo bargroup 4096  128 16:19 .svn/
-rw-r--r-- 1 foo bargroup  633  128 16:19 index.html
-rw-r--r-- 1 foo bargroup  525  128 16:19 test.html
$

差分の確認とコミット

1. 変更していない状態で差分の確認(なにも表示しない)。
2. 編集してみて差分を確認(修正内容があっているのか)。
3. 問題なければコミット。

$ svn status
$ svn diff
$ vi index.html
$ svn diff
Index: index.html
===================================================================
--- index.html (リビジョン 1)
+++ index.html (作業コピー)
@@ -23,6 +23,7 @@


+<!-- コメント追加 -->


$ svn commit -m "Add a comment."
送信しています              index.html
ファイルのデータを送信中です.
リビジョン 2 をコミットしました。
$

ファイルの追加

新規ファイルを作成した場合には、
1. ファイルを"作業コピーに追加"してSubversionの管理下に追加。
2. リポジトリに反映
を行う。つまり、"add"のあと"commitが必要。

$ vi style.css
....
$ svn status
?      style.css      ("?"なので知らないと言っている)
$ svn add style.css
A         style.css
$ svn status
A      style.css      ("A"なので追加されたと言っている)
$ svn ci -m "Add a Cascading Style Sheet."
追加しています              style.css
ファイルのデータを送信中です.
リビジョン 3 をコミットしました。
$ svn status
$

キーワードの設定

CVSでは自動でキーワードを置換してくれたが、Subversionでは、ファイルごとに設定す
る必要があるらしい。
これを設定した後にコミットすることでソースに書いてあるキーワード、例えば($Id$)な
どが置換される。

$ svn propset svn:keywords "Date Id Author" test.html
属性 'svn:keywords''test.html' にセットしました
$ svn ci -m "Add keywords."
送信しています              test.html

リビジョン 4 をコミットしました。
$ grep 'Id:' test.html
<!-- $Id: test.html 4 2009-01-28 07:55:00Z foo $ -->

propsetをしないで自動で行う場合には、"~/.subversion/config" を

$ vi ~/.subversion/config
....
enable-auto-props = yes

### Section for configuring automatic properties.
[auto-props]
*.html = svn:keywords=Date Id Author
....

のように修正することで、import/add時に設定されるようになる。詳しくは以下を参照の
こと。

http://wiki.bit-hive.com/tomizoo/pg/Subversion%20%A5%AD%A1%BC%A5%EF%A1%BC%A5%C9%A4%CE%C5%B8%B3%AB

通常作業では

通常作業する場合は該当ディレクトリにて、
1. status, updateを実行
2. ファイルの修正
3. 差分の確認
4. コミット
を繰り返せばよい。

$ svn status
$ svn update
リビジョン 2 です。
$ vi new.html
....
$ svn diff
....
$ svn ci -m "Modified ...."
....
$

リポジトリの中身(tree表示)

リポジトリの中身をtree表示で確認する。

$ svnlook tree /home/foo/SVN-repos/
/
 work/
  myproject/
   index.html
   style.css
   test.html
$