Git

新規・初期設定

repositoryを取得する

$ git clone git://git.kernel.org/pub/scm/git/git.git

違うバージョンをcheckoutする

$ git branch
* master

レポジトリを作成する

$ mkdir project
$ cd project
$ git init
$ git add . # include everything below ./ in the first commit:
$ git commit

作成、新規追加、閲覧

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 <branch> <- 現在のブランチで同じポイントで<branch>名でブランチを作成する
git branch <branch> <start-point> <- 特定のポイントのブランチを、<branch>名で作成する
git branch -d <branch> <- <branch>を削除する。もしreach出来ないブランチだったら使えない
git branch -D <branch> <- ブランチがreach出来ないが削除したい場合に使う
git checkout <branch> <- <branch>を現在のブランチにする。woking directoryに反映させる
git checkout -b <new> <start-point> <- 特定のポイントのブランチを、新しくブランチとして作成する。<start-point>はorigin/todoなど。

$ 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
 

追加して確認する
$ git branch -r
linux-nfs/master
origin/master

Bisect

$ git bisect start
$ git bisect good v2.6.18
$ git bisect bad master

masterが消え(たように見えて)HEADがcommitやpointの対象になる
v2.6.18からは行けない

テストしてダメだったら
$ git bisect bad

古いバージョンをcheckoutしてテストを繰り返す

修正すべきバージョンやファイルが分かったら、
$ git bisect reset
でリセットする

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^^ # the grandparent
$ git show HEAD~4 # the great-great-grandparent

$ git show HEAD^1 # show the first parent of HEAD
$ git show HEAD^2 # show the second 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
e05db0fd4f31dde7005f075a84f96b360d05984b

特定のcommit間を比較する

$ git diff --cached
・HEADとindex fileの間

マージしたい場所にポイントを切り替えて、branchnameを指定して取り込む

$ git merge branchname

$ git commit
file.txt: needs merge

- file.txtを修正する
$ git add file.txt
$ git commit

ポイントを切り替え、pullする

$ git checkout test && git pull
$ git checkout release && git pull

変更・修正・差し戻し

commitはまだしてない、間違っていた場合リセットする

$ git reset --hard HEAD

commitを既にしたが、間違っていた場合リセットする

$ git revert HEAD

working中だか一時的に保存したい場合にstashを使って保存する

$ git stash save "work in progress for foo feature"

通常の作業やcommitなどにする

stashしていた内容を戻して、通常作業に戻る
$ git stash pop

ブランチの修正があった為にmasterがpullできない場合

git checkout subbranch
git pull origin subbranch

作業内容を反映させる

ブランチにもpushする

$ git push mytree test

その他

アーカイブを再圧縮する

$ git gc

ファイルをチェックする

$ git fsck

$ git fetch
$ git merge origin/master

= 上下は同じ

$ 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

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2012-03-12 (月) 16:54:42 (197d)