Gitコマンドいろいろ

http://sourceforge.jp/magazine/09/03/16/0831212

git branch

現在のブランチを表示

新規branch作成

git branch name

branch切替

git checkout name

branch削除

git branch -d
\-D

リモートブランチを削除
git push origin :branchname

branch名変更

git branch -m name newname

リモートブランチをコピー

git branch -r
git fetch --prune
git branch new_branch_name origin/new_branch_name
git checkout new_branch_name
git pull origin new_branch_name

marge

マスターにマージ。
git checkout master
git merge branchname

最新のmasterを作業ブランチへ取り込む

git checkout master
git pull origin master
git checkout hoge
git merge master
コンフリクトが発生した場合(bot modified)
vi file
add file
commit

git add

ステージングにファイルを追加する。

ファイル指定

git add file file

管理下のファイル全て

git add .

変更が加えられたファイルと、未追跡だったファイル

git add --all

add 取り消し

git reset HEAD file

修正を戻す

git reset --hard

git commit

コミット。ステージングファイル全て

ファイル指定

git commit file file

取り消し

直前のコミットをやり直す、上書き。
git commit --amend

git reset --soft :ワークディレクトリの内容はそのままでコミットだけを取り消す。
git reset --hard :コミットを取り消し&ワークディレクトリの内容も書き換え。
直前の間違ったコミットを取り消したい。
git reset --soft HEAD^
(HEAD^は直前のコミットを表す)

ログ

git log
git log --oneline

diff表示

git log -p

過去のコミットを検索

git log -S 'hoge'

diff

二つのコミットの差分を表示する
git diff commit1 commit2

clone

リモートリポジトリをローカルへコピー
git clone path app_dir

リモートから特定のブランチを指定してcloneする方法
git clone -b ブランチ名 https://リポジトリのアドレス

tag

タグを指定してclone
git clone --depth=1 -b v2.0494 https://github.com/path.git

git pull

リモートリポジトリの内容をローカルリポジトリにマージ。
※後で調べる

git pull --rebase
リポジトリの変更をマージせずにローカルへ。

git push

リモートリポジトリへ反映
git push origin master

ブランチを指定
git push origin ローカルブランチ:リモートブランチ

強制上書き
\-f

ブランチ削除
git push origin :branch-name

git stash

http://qiita.com/fukajun/items/41288806e4733cb9c342
作業ファイルの退避
git stash
git stash list
git stash apply stash@{0}
git stash drop stash@{0}
差分確認
git diff stash@{0}
git diff stash@{0} hoge.txt

git remote

リモートリポジトリを登録
git remote add
設定削除
git remote rm origin

git checkout

作業ディレクトリの状態を戻す
git checkout .
git checkout file
ファイルの削除は行われない。

git config

リポジトリの設定表示
git config -l

ユーザー情報設定
git config --global user.name name
git config --global user.email email

pullに失敗した時

You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you can merge.
fetchしreset

$ git fetch origin
$ git reset --hard FETCH_HEAD

特定のファイルの変更を無視する

git update-index --assume-unchanged [path]

解除

git update-index --no-assume-unchanged [path]

管理下から除外

git rm --cached [ファイル名]
git add -u