リポジトリの作成
git init git init name git init --bare git init --shared
gitリポジトリの設定
git config git config --global
ファイルをインデックスに登録する
git add file git add --all
差分を出力する
git diff git diff file git diff commit1 commit2 git diff HEAD git diff --cached git diff --cached -M
コミットログの表示
git log git log commit1..commit2 git log branch file git log -p git log -3 git log -3 commit git log --date-order git log --oneline git log --pretty=<%h %ci %s> git log --decorate --graph
ローカルリポジトリ、ワーキングツリーの状態を確認する
git status git status -s git status -sb
ディレクトリ、ファイルの移動、変更を行う
git mv file_before file_after git mv -f file_before file_after
ディレクトリ、ファイルの削除を行う
git rm file git rm --cached file git rm -r dir
ローカルリポジトリにコミット
git commit git commit -m git commit -a git commit file git commit --amend
ローカルリポジトリ、インデックス、ワーキングツリーをもとに戻す
git reset --hard commit1 git reset --soft commit1 git reset --mixed commit1 git reset --mixed commit1 file
ワーキングツリーを掃除する
git clean git clean -n git clean --dry-run git clean -f git clean -fd
ファイルから文字列を検索する
git grep string git grep string file git grep --cached string git grep --no-index string git grep -e string git grep -f pattern_file git grep -e string1 --[and|or|not] -e string2 ... git grep -i string git grep --ignore-case string
リポジトリで管理しないファイルを設定する
echo 'file' > .gitignore echo '!file' > .gitignore
コミット内容を表示する
git show git show commit
リモートリポジトリをローカルにコピーする
git clone git://xxx.org/remote.git git clone git://xxx.org/remote.git git clone -b branch git://xxx.org/remote.git git clone -o repos_name git://xxx.org/remote.git git clone --bare git://xxx.org/remote.git
リモートリポジトリの管理、更新を行う
git remote add repos_name git://xxx.org/remote.git git remote -v git remote show repos_name git remote update git remote update repos_name git remote rm repos_name git remote prune
ブランチをマージする
git merge branch git merge --squash branch
リモートリポジトリにローカルリポジトリのデータを送信する
git push remote_repo local_branch:remote_branch git push remote_repo :remote_branch
ローカルリポジトリにリモートリポジトリのデータを反映する
git pull remote_repo local_branch git pull remote_repo git pull
ローカルブランチの作成、削除、確認、トラッキング
git branch git branch -r git branch -a git branch branch_name git branch root_branch new_branch git branch -v git branch -m old_branch_name new_branch_name git branch -r branch_name
ファイルの特定の行が最後に編集された履歴を追跡する
git blame file git blame commit file git blame -L 3,7 file git blame -L 3,+5 file git blame -C30 file git blame -M file
ブランチをインデックスとワーキングコピーに展開する
git checkout branch_name git checkout branch_name file git checkout -f git checkout -b branch_name
タグをつける
git tag name commit git tag -m "message" name git tag -s name git tag -d name
最も近いタグを表示する
git describe
リポジトリのスナップショットを作成する
git archive --format=tar --prefix=dir/ HEAD > ../snapshot.tar git archive --format=tar --prefix=dir/ HEAD src_dir1/src_subdir1/ src_dir2/src_subdir2/ > ../snapshot.tar git archive --format=tar --prefix=dir/ --remote=origin master > ../snapshot.tar
リモートリポジトリからリポジトリデータを取得する
git fetch git://xxx.org/xxx.git branch_name
未コミットの状態を一時的に保存する
git stash save name
git stash list
git stash show -p stash@{0}
git stash pop
git stash drop stash@{0}
git stash clear
コミットした内容を取り消す
git revert ':/commit comment' git revert -n HEAD~4
指定したブランチの最新コミットに追従させる
git rebase branch_name git rebase --continue git rebase --abort git rebase --skip git rebase -i branch_name
コミットをメール形式で出力する
git format-patch -o out_dir/ origin/master
パッチをメールで送信する
git send-email --to [email protected] filename.patch git send-email --to [email protected] out_dir
メールで送られてきたパッチを取り込む
git am patch_dir/*
pull申請用の情報を出力する
git request-pull master git://xxx.org/xxx.git branch_name
ブランチに含まれていないコミットを調べる
git cherry -v dist src
特定のコミットをブランチに取り込む
git cherry-pick commit
バグが入り込んだコミットを特定する
git bisect start commit1 commit2 git bisect good git bisect bad git bisect reset git bisect run make
ブランチの状態を表示する
git show-branch
他のリポジトリをモジュールとして利用する
git submodule add git://xxx.org/xxx.git git submodule status git submodule init git submodule update
リポジトリのオブジェクトを掃除する