2013年2月26日火曜日

git flow まとめ

git flow

install


$ brew install git-flow

 git flow
 usage: git flow 
 
 Available subcommands are:
     init      Initialize a new git repo with support for the branching model.
     feature   Manage your feature branches.
     release   Manage your release branches.
     hotfix    Manage your hotfix branches.
     support   Manage your support branches.
     version   Shows version information.
 
 Try 'git flow  help' for details.

git flow init

  Which branch should be used for bringing forth production releases?
     - master
  Branch name for production releases: [master] 
  Branch name for "next release" development: [develop] dev
  
  How to name your supporting branch prefixes?
  Feature branches? [feature/] 
  Release branches? [release/] 
  Hotfix branches? [hotfix/] 
 Support branches? [support/] 
 Version tag prefix? [] v

git flow feature

feature ブランチの流れ
  #機能追加を始めますよ
  $ git flow feature start [-F]  []
  
  #編集してコミットする
  $ git commit -a -m 'add code' 
  
  $ git checkout dev && git pull

  $ git checkout feature feature/

  #機能追加完了
  $ git flow feature finish [-rFkDS] [] # -k で branchが消えない
  
 #pull
 $ git pull
 
 #リモートのdevブランチにpush
 $ git push
git flow feature で使えるコマンド

git flow  help
  git flow feature [list] [-v]
  git flow feature start [-F]  []
  git flow feature finish [-rFkDS] []
  git flow feature publish 
  git flow feature track 
  git flow feature diff []
  git flow feature rebase [-i] []
  git flow feature checkout []
  git flow feature pull [-r]  []

git flow hotfix

 git flow hotfix start [-F]  []
 working...
 $ git add 
 $ git commit
 $ git checkout dev && git pull # 最新にしとく
 $ git checkout master && git pull # 最新にしとく
 $ git flow hotfix finish [-Fsumpk] 
 # master と dev にマージされてtagができるから 
git flow hotfix で使えるコマンド finishするまでの間にmasterが更新された場合は諦めてマージするのが正しい pull --rebaseもNG fetch & rebaseだからね rebaseはcommitIDを変える dev, masterが古かったことに気付いたときは、一旦dev, masterをcheckoutし直してfinishをやり直すと言う方法もある (git flow hotfix finish -k hogeでhotfixブランチを残しておけばそれも可能) ※masterを更新しわすれたりしたとき
$git fetch; git rebase -p origin/master
-pはhotfixのマージコミットを残す。

# dev
git fetch; git rebase -p origin/dev

git flow release

  #devブランチとmasterブランチを最新化しておく
 $ git pull
 #devブランチでsubtreeをpullする (最新化する)
 $ git subtree pull --prefix=shared git@github.com:yanap/frma-shared.git master
 #pushする
 $ git push
 #リリースブランチをはじめる
 $ git flow release start 1.0.1
  #リリースブランチをおわる
 $ git flow release finish 1.0.1
 #タグを確認する
 $ git tag -n
 #pushする
 $ git push origin master
 $ git push origin v1.0.1
 #途中コンフリクトがおきたとき
 $ git checkout --theirs
 $ php -l 
 $ git add
 $ git commit
 #でなおして途中で終了してしまうので消してやり直すかcheckoutしなおして finishからやり直す

参考

見えないチカラ: A successful Git branching model を翻訳しました
successful Git branching model を補助する git-flow を使ってみた - Twisted Mind
ぼくが実際に運用していたGitブランチモデルについて ::ハブろぐ

2013年2月25日月曜日

git まとめ

gitを使ってみて良く使うことだけをまとめる

git --help

git コマンド一覧がでてくる

git command --help

git コマンドごとの詳しい説明がでてくる
でも、英語なので、ここで理解できずにggrことになる

git clone

git clone git@github.com:yanap/dotfiles.git
リポジトリを自分のパソコンにダウンロードする

git add

新規作成したファイルをgitに追加する

git commit

その時点での進捗具合をセーブす的なコマンド
セーブした所にすぐ戻れる

git commit -a

addを同時に行う

git commit -a -m "comment"

addとコメント入力を同時に行う

git commit -a -m "comment" --dry-run

ドライラン

git commit --amend

セーブするポイントを間違えたときにセーブを上書きする

git push origin [local<branch>]:[remote<branch>]

git push origin dev:dev

local branch : remote branch

でも、普段はlocal branchは省略しても大丈夫なので
git push origin dev

remote branchを消したいときは
git push origin :delete_branch
NULL:delete_branch
NULLを対象のremote branchにpushするので、指定された
remote branchは削除される

git checkout

git checkout [<branch>]

git checkout master 作業環境をmasterに変える
git checkout dev 作業環境をdevに変える

git checkout -b [<branch>]

ブランチ作成とブランチ切り替えを同時に行う

git checkout -t origin/[<branch>]

リモートにあるブランチをローカルにダウンロードすると同時に
ブランチを切り替える。

git pull origin [remote <branch>]

remoteのbranchをダウンロードしてlocalのbranchにマージする
git pull origin devはgit fetach origin dev
してgit merge origin dev している