バージョン管理を使うと、変更履歴が効率良く行う事ができるようになる。
最近のバージョン管理では、さらに複数名での活動をサポートしてくれるようになっているので、これを使って開発をするようにしましょう。
Git の産みの親は Linux kernel の産みの親でもある Linus Torvalds 氏
この仕組みが使われLinuxのKernelが開発されている。
Git の特徴は、"分散型"のバージョン管理システムであるということ 集中型と違い、ローカルで管理を行いつつ、必要なときに中央サーバに接続をする
殆どのが作業がローカルで行われるので、オフライン時でも利用する事が出来る
http://git-scm.com/book/ja/使い始める-バージョン管理に関して
"分散型"というのは、リポジトリが1箇所に集中していないという意味です。 集中型の場合は、中央サーバで障害が発生すると全員が影響を受けてしまうという深刻な課題があります。
Gitには4つの場所があります。
- 中央サーバ
- Gitディレクトリ(ローカル)
- ステージングエリア
- 作業ディレクトリ(ローカル)
作業ディレクトリは実際に編集を行ったり、中央サーバから取得した内容を反映されたりする場所
中央サーバは参加する全員が他の人にも伝えたい変更点を登録する場所
ステージングエリアは幾つか行った編集作業結果のうち、管理対象にしたいものを登録する場所
GitディレクトリはGitで操作するために必要となるファイルなどが格納されているローカルの領域、コミットされるとこの領域に登録がおこなわれる。
- gitコマンドをインストールする
Windowsならばgitでも良いが、SourceTreeはかなりお勧め
$ git config --global user.name "John Doe"
$ git config --global user.email [email protected]
- cloneしてPush
- 従来のやり方のまま
- cloneしてPullRequest
- ソースコードのレビューを含める
- forkしてPush
- 公開されているものを改造して使う感じ
- forkしてPullRequest
- 公開されているものを修正して、製作者へ教える(オープンソースの開発)
チームでの開発の場合は2が良い。
http://www.backlog.jp/git-guide/intro/intro5_1.html
http://ko8h.hatenablog.com/entry/2013/07/10/141132
- clone / pull
- branch
- 作業 & commit
- push
- PullRequest
- 3名で本を書く
- masterブランチへのpushは禁止
- PullRequestを使い、他の2名が査読する
- 各作業はbranchを切って行う
- フォーマットはMarkDownを使うこと
- リポジトリはBitbucketを使う
- [email protected]
- プロジェクトリーダー
- [email protected]
- お手伝い
- [email protected]
- メインライター
- リポジトリの準備と招待
- bitbucketでリポジトリ作成
- Nitrousでbox作成
- git config
- mkdir , cd, giti init, git remote add
- ファイル作成
- git add, git commit, git push -u origin master
- Bitbucketで招待する
- リポジトリをクローンする
- nitrousでbox作成
- git clone https://[email protected]/yoshidayuya/gitstudy.git
- Read.me に書き加えてみよう
- git diff, git status, git commit, git push -u origin master
- git checkout -- filename
- リポジトリ確認と自分のところに持ってくる
- git pull
- 自分の名前を追記
- git diff, git add ., git commit, git push
- git pull
同時に同一ファイルを書き換えて反映する
- Readme.mdにて名前を変更する
- git add . , git commit, git pushする
- Readme.mdにて名前を変更する
- git add . , git commit, git pushする
! [rejected] master -> master(fetch first)
error: failed to push some refs to 'https://[email protected]/yoshidayuya/gitstudy.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first merge the remote changes (e.g., hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
conflictしたので競合の修正を手動で行う。エディタで開き、修正を行う。
保存したらcommitして、pushする。 競合が解消した後のコミット履歴を見てみよう。
- 準備の手順
- ここまでの作業を振り返り、これが3名4名と増えてきた場合を想像してみよう。
- ここまでの作業における課題点とどのような状況が理想的かを考えてみよう
リーダー、作業者両方ともブランチを切って作業を始める。
- リーダーは第1章を担当する
- 作業者は第2章を担当する
以降、masterブランチへのcommitはマージのみとする。
rebaseとfast fawordはさせないようにします。
はじめにを書いてみましょう。
$ git branch atfirst
$ git branch
$ git checkout atfirst
新しくファイルを作成して「はじめに」を書きます。
-
ファイル名は00_atfirst.md
-
書き終わったら保存します。
-
git statusで確認
-
git add, git commitを行う
-
git push -u origin atfirst
-
Bitbucketで確認してみよう
-
作業者はmasterのままpullしてみるどうなるか。
- atfirstブランチの情報が取得できる
-
atfirstをcheckoutするとどうなるか
- 00_atfirst.mdが現れて閲覧できる
マージ前にcommit忘れがないかgit status等で確認すること。
- git checkout master
- ls : まだ00が無いことを確認する
- git merge atfirst
Fast-fowardと表示されている。bitbucketを見てみよう
- git add, git commit
- git push
Bitbucketを見てみよう。
atfirstブランチはこれで終わりなので、削除する。 (ローカルから削除されるだけ)
- コミット履歴からatfirstを見てみよう
- はじめにの作業用に作ったはずが、なんだかいろいろあるなぁ
作業者
- git pull
- git checkout master
- git pull
- git branch -v
管理者がブランチを削除したが、作業者の方は消えていない。
fast-forwardされた結果、masterがatfirstの前に来た。がわかりにくいので、禁止にする
- git config --global --add merge.ff false
作業者があとがきを書こう。ブランチは2つ切る。
- develop
- developからatlastを切る
developは作業が終わったらマージする先として使う。 developからmasterへのmergeは管理者が行うものとする。
-
git branch develop
-
git checkout develop
-
git push -u origin develop
-
git branch atlast
-
git checkout atlast
-
git push -u origin atlast
-
vim 99_atlast.md
-
git add
-
git commit
-
git push -u origin atlast
-
git checkout develop
-
git merge atlast
- :q で終わらせる
-
git push -u origin develop
bitbuchket を確認
- masterブランチは特に何も起きていない
- developにatlastが発生している
管理者はdevelopが問題なければ、masterへマージする
- git pull
atlastとdevelopが降ってくる
- git checkoutでdevelopへ
- 99_last.mdを確認する
- 問題なければcheckoutでmasterへ
- git merge develop
- git push
-
各章はディレクトリを作成して書くこと
-
名前は01-99
-
本文はbody.mdとする
-
developブランチからcreate_XXというブランチを切って作業すること。
-
作業が完了したらdevelopへmergeする
これまでの作業がすべてdevelopにマージされたら、最後にPullRequestを使いMasterへのマージを依頼してみます。
- 作業者はBitbucketの画面にてプルリクエストを作成し、レビュアーに管理者を設定しましょう
http://www.slideshare.net/himaratsu/bitbucket-pull-request