gitosis on mac os x server

24
Git の基本と gitosis :-) #35 2011/04/09 Itabashi, Yasuhiro Asaka

Upload: yasuhiro-asaka

Post on 17-May-2015

2.038 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Gitosis on Mac OS X Server

Git の基本とgitosis :-)

#352011/04/09Itabashi, Yasuhiro Asaka

Page 2: Gitosis on Mac OS X Server

自己紹介

¶ About me

Page 3: Gitosis on Mac OS X Server

Yasuhiro Asaka whoami

‣¶ プログラマ‣¶ Ruby,Objective-C,Mac OS X Server ‣¶ 小松菜 じゃがいも えんどうまめ‣¶ Arduino

‣¶ Apple Certified Help Desk Specialist 10.4‣¶ Ruby Association Certified Ruby Programmer Silver.‣¶ @grauwoelfchen‣¶ http://www.grauwoelfchenslabor.com/

Page 4: Gitosis on Mac OS X Server

議題

¶ Agenda

Page 5: Gitosis on Mac OS X Server

¶ gitosis を使う - Mac OS X Server 10.5 で - Account、Remote repository 追加 [Demo]

¶ Git の特徴 - 特徴、基本機能

Page 6: Gitosis on Mac OS X Server

特徴、基本機能

¶ Git の特徴

Page 7: Gitosis on Mac OS X Server

** 特徴 **¶分散型 VCS、ローカルリポジトリ・ブランチ

¶インデックス

¶コマンドが多い (便利 && 複雑)

¶高速 (zlib圧縮、git プロトコル、マージ)

中央集約型 分散型

運用方法しだい ...1 対多

Page 8: Gitosis on Mac OS X Server

master

¶ローカルブランチ

Sinatra でみかけた例 (on github)

実験的な(他の人に影響しない)ブランチを簡単に作れる

平行した作業が進められる

複数コミットにまたがる論理的な変更の単位やリリース

Page 9: Gitosis on Mac OS X Server

¶インデックス

コミットとワークツリーの中間に位置

ステージングエリアとも呼ばれる

ステージ・アンステージして、コミットするための内容を作る場所

インデックスに含まれる一部(ハンク)だけをコミットもできる

Commit

Index

Working tree

git add

git commit

Page 10: Gitosis on Mac OS X Server

Awesome Terminal - bash - ⌘ 1

$ mkdir test && cd test$ git init # => 初期化Initialized empty Git repository in /path/to/test/.git/$ echo test > test.txt$ git status # => 状態の確認# On branch master## Initial commit## Untracked files:# (use "git add <file>..." to include in what will be committed)## test.txtnothing added to commit but untracked files present (use "git add" to track)$ git add -A # => ステージング$ git status # => 状態の確認# On branch master## Initial commit## Changes to be committed:# (use "git rm --cached <file>..." to unstage)## new file: test.txt#$ git commit -m ‘created test.txt’ -m ‘initial commit !’ # => コミット[master (root-commit) a7d81b8] created test.txt 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 test.txt

Page 11: Gitosis on Mac OS X Server

¶分散型のワークフロー

1. クローン # => リモートから歴史ごと取得

2. 編集

3. ステージング # => インデックスに追加

4. コミット # => ローカルリポジリへ記録

5. プッシュ # => リモートリポジトリへ記録

1. フェッチ # => リモートへの変更の取得

2. マージ # => ワーキングツリー、ブランチへマージ

リポジトリ作成 - ワーキングツリーの変更を記録

1. プル # => フェッチしてマージ

リモートの変更取り込み

または ...

Page 12: Gitosis on Mac OS X Server

** 基本機能 ** Git に限らず ...¶論理的な複数ファイルにまたがる変更の記録

¶以前のコミットに戻る

¶変更履歴を調べる

¶なぜと誰がの記録Awesome Terminal - bash - ⌘ 1

$ git config -l # => svn info に相当user.name=grauwoelfchenuser.email=grauwoelfchen@gmail.comcolor.ui=auto # => カラー表示core.autocrlf=input # => コミット時に改行コードをLFに揃えるcore.excludesfile=/Users/grauwoelfchen/.gitexclude # => 共通の無視設定ファイルcore.repositoryformatversion=0core.filemode=truecore.bare=falsecore.logallrefupdates=truecore.ignorecase=trueremote.origin.fetch=+refs/heads/*:refs/remotes/origin/*[email protected]:foo.git # => リモートリポジトリremote.moxssg.fetch=+refs/heads/*:refs/remotes/moxssg/*[email protected]:foo.git # => リモートリポジトリ

Page 13: Gitosis on Mac OS X Server

Awesome Terminal - bash - ⌘ 1

$ git log -3 -p Gemfile # => ‘Gemfile’ というファイルを扱ったコミットの内容を3つcommit 9d3f4bc38f2d89d98567af017cf0327626e4effaAuthor: grauwoelfchen <[email protected]>Date: Sun Apr 3 23:39:49 2011 +0900

specified version of maruku gem.

diff --git a/Gemfile b/Gemfileindex 99fa1f0..df7bac2 100644--- a/Gemfile+++ b/Gemfile@@ -7,7 +7,7 @@ gem 'bson_ext', '~> 1.2' gem 'data_mapper' gem 'mongoid_taggable' gem 'will_paginate', '~> 3.0.pre2'-gem 'maruku'+gem 'maruku', '~> 0.6.0' group :development do gem 'rspec', '2.5.0'commit 878ecc909708a46dfc1c85b23ed2c344b5343032:

¶変更履歴を調べる

¶なぜと誰がの記録

Page 14: Gitosis on Mac OS X Server

Awesome Terminal - bash - ⌘ 1

# 指定したファイルに関連するコミット数を調べる$ git rev-list --all Gemfile | wc -l6

# 指定したファイルの各行の変更がどのコミットからきたかを調べる$ git blame Gemfile497c0e86 (jobs 2011-03-09 11:57:22 +0900 1) source :gemcutter497c0e86 (jobs 2011-03-09 11:57:22 +0900 2) 878ecc90 (jobs 2011-03-22 03:20:17 +0900 3) gem 'sinatra', '~> 1.2.0'497c0e86 (jobs 2011-03-09 11:57:22 +0900 4) gem 'haml', '3.0.25'497c0e86 (jobs 2011-03-09 11:57:22 +0900 5) gem 'mongoid', '2.0.0.rc.7'd2560ba3 (jobs 2011-03-21 11:59:52 +0900 6) gem 'bson_ext', '~> 1.2'

# 特定のファイルにおける、あるコミットでの変更内容を調べる$ git show HEAD~3 Gemfilecommit 9d3f4bc38f2d89d98567af017cf0327626e4effaAuthor: grauwoelfchen <[email protected]>Date: Sun Apr 3 23:39:49 2011 +0900

specified version of maruku gem.

diff --git a/Gemfile b/Gemfileindex 99fa1f0..df7bac2 100644--- a/Gemfile+++ b/Gemfile@@ -7,7 +7,7 @@ gem 'bson_ext', '~> 1.2' gem 'data_mapper'-gem 'maruku'+gem 'maruku', '~> 0.6.0'

Page 15: Gitosis on Mac OS X Server

変更の検知 > git blame

歴史の書き換え > git rebase

ワークツリーの変更取り消し > git checkout

インデックスの変更取り消し > git reset

コミットの変更取り消し > git reset --hard

コミットの打ち消し > git revert

変更を一時横に置いておく > git stash

ブランチのマージ > git merge branch名

ローカルブランチ作成 > git checkout -b branch名

リモートのブランチ削除 > git push [remote] :branch名

¶よく使うコマンド

¶よく使うフックpre-commit フック (コミットの内容チェックなど)

commit-msg フック (メッセージの統一など)

post-update フック (push を受けてデプロイさせたり)

Page 16: Gitosis on Mac OS X Server

¶他の分散VCS と比較 リクエストいただきましたが ...

コマンド、ツールの違いこそあれ、

ワークフローはあんまり違わない。 ...と思う

svnからの切り替え先にbzrを検討するなど(最終的にはhgになった‥)http://togetter.com/li/91517

分散バージョン管理Git/Mercurial/Bazaar徹底比較http://www.atmarkit.co.jp/fjava/rensai4/devtool03/devtool03_1.html

Page 17: Gitosis on Mac OS X Server
Page 18: Gitosis on Mac OS X Server

大切なのは ツールの優劣ではなく

どう使うか (いいわけ)

Page 19: Gitosis on Mac OS X Server

Mac OS X Server へインストール

¶ gitosis を使う

Page 20: Gitosis on Mac OS X Server

** 目的,ニーズ **

¶ssh でセキュアに通信したい

¶公開鍵の登録が煩雑

¶シェルアクセスはさせたくない

¶リモートリポジトリ作成を簡単にしたい

¶リポジトリ単位でアクセス権を設定したい

Page 21: Gitosis on Mac OS X Server

** 目的,ニーズ **

¶ssh でセキュアに通信したい

¶公開鍵の登録が煩雑

¶シェルアクセスはさせたくない

¶リモートリポジトリ作成を簡単にしたい

¶リポジトリ単位でアクセス権を設定したい

→ gitosis-admin.git で管理

Page 22: Gitosis on Mac OS X Server

¶/home/git が /Users/git になる

¶/Users/git/.bashrc で git (コマンド) へパス通す

¶Server Admin で git ユーザに SSH を許可

** OS X Server の場合 **

Awesome Terminal - bash - ⌘ 1

# gitosis インストール$ python --versionPython 2.5.1$ git clone git://eagain.net/gitosis.git$ cd gitosis$ sudo python setup.py install...

# ユーザ作成# dscl . -create /Users/git# dscl . -create /Users/git UserShell /bin/bash# dscl . -create /Users/git RealName "git"# dscl . -create /Users/git NFSHomeDirectory /Users/git# dscl . -create /Users/git UniqueID xxx# dscl . -create /Users/git PrimaryGroupID xxx# createhomedir -b -u git

Page 23: Gitosis on Mac OS X Server

Awesome Terminal - bash - ⌘ 1

# もしすでに管理しているリポジトリたちがどこかにあれば$ ln -s /srv/repos/git /Users/git/repositories$ sudo chown -R git /Users/git/repositories

# ローカルで (管理者の公開鍵を転送しておく)$ scp ~/.ssh/id_rsa.pub [email protected]:/tmp/git # => ローカルマシン...

# gitosis 初期化$ sudo -H -u git gitosis-init < /path/to/id_rsa.pubInitialized empty Git repository in /srv/repos/git/gitosis-admin.git/Reinitialized existing Git repository in /srv/repos/git/gitosis-admin.git/...

# post-update フックのアクセス権修正$ sudo chmod 755 /srv/repos/git/gitosis-admin.git/hooks/post-updat

# git コマンドへの PATH を通す$ touch ~/.bashrc$ echo PATH=/usr/local/bin:\$PATH > .bashrc # => brew install git していた時$ echo export PATH >> .bashrc

# インストール完了 !!

# 動作確認、ユーザ追加、リポジトリ追加のデモ$ sudo demo

Page 24: Gitosis on Mac OS X Server

Awesome Terminal - bash - ⌘ 1

$ exitlogout

[My LT completed]

# ありがとうございました