新規・初期設定 †repositoryを取得する †$ git clone git://git.kernel.org/pub/scm/git/git.git 違うバージョンをcheckoutする †$ git branch * master レポジトリを作成する †$ mkdir project 作成、新規追加、閲覧 †Tagを見る †※Tagは、プロジェクトのヒストリーを参照 $ git tag -l v2.6.11 v2.6.11-tree v2.6.12 v2.6.12-rc2 ... 特定のバージョンをブランチとして作成する †$ git checkout -b new v2.6.13 $ git branch master * new もしnewがいやならば $ git reset --hard v2.6.17 Branch情報 †git branch <- 全部のbranchesを表示 $ git branch -r <- remoteの意味 origin/HEAD origin/html origin/maint origin/man origin/master <- HEADのコピー origin/next origin/pu origin/todo 他のレポジトリから別のブランチを追加する †$ git remote add linux-nfs git://linux-nfs.org/pub/nfs-2.6.git $ git fetch linux-nfs * refs/remotes/linux-nfs/master: storing branch 'master' ... commit: bf81b46 追加して確認する Bisect †$ git bisect start masterが消え(たように見えて)HEADがcommitやpointの対象になる テストしてダメだったら 古いバージョンをcheckoutしてテストを繰り返す 修正すべきバージョンやファイルが分かったら、 Naming commits †$ git show fb47ddb2 # the first few characters of the object name # are usually enough to specify it uniquely $ git show HEAD^ # the parent of the HEAD commit $ git show HEAD^1 # show the first parent of HEAD $ git fetch git://example.com/proj.git theirbranch $ git tag stable-1 1b2e1d63ff Generating diffs †$ git diff master..test $ git rev-list origin 特定のcommit間を比較する †$ git diff --cached マージしたい場所にポイントを切り替えて、branchnameを指定して取り込む †$ git merge branchname $ git commit
ポイントを切り替え、pullする †$ git checkout test && git pull 変更・修正・差し戻し †commitはまだしてない、間違っていた場合リセットする †$ git reset --hard HEAD commitを既にしたが、間違っていた場合リセットする †$ git revert HEAD working中だか一時的に保存したい場合にstashを使って保存する †$ git stash save "work in progress for foo feature" 通常の作業やcommitなどにする stashしていた内容を戻して、通常作業に戻る ブランチの修正があった為にmasterがpullできない場合 †git checkout subbranch git pull origin subbranch 作業内容を反映させる †ブランチにもpushする †$ git push mytree test その他 †アーカイブを再圧縮する †$ git gc ファイルをチェックする †$ git fsck $ git fetch = 上下は同じ $ git pull origin master Conflict †コンフリクトして自分のデータを採用 $git checkout --ours application/gen.sh コンフリクトして相手のデータを採用 $git checkout --theirs application/gen.sh git commit ちなみにコンフリクトしたファイルの確認はgit ls-files -u conflictしたファイルを確認する †$ git ls-files -u |