まず、テスト用のファイルを用意する。
$ mkdir testdir $ cd testdir $ echo "hello" > hello.txt $ ls -a . .. hello.txt $ cat hello.txt hello次に、このディレクトリをgitで管理するためにリポジトリを作成し、そこにカレントディレクトリの内容をすべて追加する。
$ git-init-db $ git-add . $ ls -a . .. .git hello.txt.gitというファイルが作成されていることがわかる。これがgitのリポジトリになる。 ここで、直接hello.txtを編集して、commitする。
$ echo "bye" >> hello.txt $ cat hello.txt hello bye $ git-commit -a Committing initial tree 42e387d3ccd3afe14d91453acca58e31be679a6c次に、CVSのように使うことを考える。testdirのクローンtestdir1を作成し、そのtestdir1/hello.txtを編集して、その変更をtestdirへ反映させる。まずは、クローンを作成する。
$ cd .. $ ls -a . .. testdir $ git-clone testdir testdir1 Generating pack... Done counting 3 objects. Deltifying 3 objects. 100% (3/3) done Total 3, written 3 (delta 0), reused 0 (delta 0) $ ls -a . .. testdir testdir1次に、testdir1/hello.txtを編集して差分を見る。
$ cd testdir1 $ echo "bye" > hello.txt $ cat hello.txt bye $ git-diff diff --git a/hello.txt b/hello.txt index 410ca14..b023018 100644 --- a/hello.txt +++ b/hello.txt @@ -1,2 +1 @@ -hello byeこの変更をcommitしてログを見る。
$ git-commit -a $ git-log ".git/COMMIT_EDITMSG" 10 lines, 210 characters written commit dd0ef1b14c2ff8743ff505c0fe677ff8d014a660 Author: U-TATE-T43\ttateこのままでは、testdir1での変更がcommitされただけで、この変更はtestdirにはまだ反映されていない。試しに、testdir2というクローンをtestdirから作って見る。Date: Sat Aug 5 05:24:57 2006 +0900 removed the first line. commit a537a5d75869aedd237edae2fdf3556e1026d485 Author: U-TATE-T43\ttate Date: Sat Aug 5 05:18:05 2006 +0900 initial commit.
$ cd .. $ git-clone testdir testdir2 $ cat testdir2/hello.txt hello bye反映させるためには、git-pushを使う。
$ cd testdir1 $ git-push updating 'refs/heads/master' from a537a5d75869aedd237edae2fdf3556e1026d485 to dd0ef1b14c2ff8743ff505c0fe677ff8d014a660 Generating pack... Done counting 5 objects. Result has 3 objects. Deltifying 3 objects. 100% (3/3) done Total 3, written 3 (delta 0), reused 0 (delta 0) Unpacking 3 objects 100% (3/3) done refs/heads/master: a537a5d75869aedd237edae2fdf3556e1026d485 -> dd0ef1b14c2ff8743ff505c0fe677ff8d014a660 $ cd .. $ git-clone testdir testdir3 $ cat testdir3/hello.txt bye以上のようにして、cvsのように使うことができるし、また、git-cvsserverというcvsをエミュレートするサーバもgitに含まれている。