なにこれ
gitを運用する上での知識の整理。
initial settings
git config --global user.name "<username>" git config --global user.email "<mail address>"
create
create new repository
git init
create new public repository
- 慣例としてディレクトリ名に.gitをつける。
- --bareをつけると、bare repositoryになる。bare repositoryは管理情報のみを持つ。
- commitなどができない。
git --bare init
clone
clone local repository
- 既存のlocal repositoryを複製する。
git clone /path/to/repository
clone remote repository
- 既存のremote repositoryを複製する。
git clone username@host:/path/to/repository
check
check status
- working directoryとindexの状態を確認する。
git status
check repository log
- repositoryの変更履歴を確認する。
git log
add/remove
add files
- indexにaddする。
git add <filename>
- すべてをaddする。
git add *
remove files
- indexからremoveする。
git rm <filename>
commit
commit
git commit -m <message>
push/pull
add remote repository
- push/pullするためにremote repositoryを予め登録しておく。
git remote add <name> <url>
- 通例次のように使う。
- push/pullでrepository名を省略するとoriginという名前につなぎに行こうとするので。
git remote add origin <remote repository url>
push
<repository>に<branch>をpushする。
- cloneして生成したrepositoryではgit pushだけでgit push origin masterと同じ事になる。
git push <repository> <branch>...
pull
<repository>をとってきて<branch>にmergeする。
git pull <repository> <branch>
branch
- 最初はmasterというbranchが作られる。
masterとtopic branch
- masterからtopic branchをを作成。
- topic branchでの変更が終わったら、masterへmerge。
head
- 現在使用しているbranchの先頭。
- デフォではmasterの先頭。
stash
- branchに対して何らかの変更を行った状態でbranchを切り替えると、その変更は切替先のbranchに引き継がれる。
- 同じファイルが切替先のbranchで既に変更されているとconflictしてしまう。
- 切替元branchにcommitしてから切り替えるか、一時的にstashと呼ばれる領域に変更を退避する。
merge
- branchを統合する事を考える。
- branch Aからbranch Bが分岐し、branch Bに変更を行った後branch Aとbranch Bをmergeすることを考える。
- branch Aに何の変更も行われていなければ、branch Aの先頭をhead(=branch Bの先頭)にするだけでmerge完了。
- fast-forward mergeという。
- branch Aに変更が行われている場合は、両方の変更を取り込んだ新しいcommitを作成する。
- headは新しいcommitに移動する。
rebase
- branch Aからbranch Bが分岐し、branch Bに変更を行った状態を考える。
- この状態でrebaseするとbranch Aの後ろにbranch Bの変更が付け足される。
- branch Aはそのままなので、branch Aの先頭をheadに移動するにはmergeを行えば良い。
A successful git branching model
in Japanese : http://keijinsonyaban.blogspot.jp/2010/10/successful-git-branching-model.html
in English : http://nvie.com/posts/a-successful-git-branching-model/
create branch
git branch <branchname>
list branch
git branch
checkout branch
- branchの切替
git checkout <branch>
merge branch
<commit>という名前のbranchがheadの指しているbranchにmergeされる。
git merge <commit>
delete branch
git branch -d <branchname>
correct conflict
- conflictによってmergeに失敗した時はどうするか。
- conflict箇所を修正してからcommitすればよい。
rebase branch
<branch>にたいしてrebase。
git rebase <branch>
- conflictによって失敗した場合は該当箇所を修正し、
git rebase --continue