gitコマンド

imageプラグインエラー : 画像を取得できませんでした。しばらく時間を置いてから再度お試しください。

Gitによるバージョン管理

ローカルリポジトリに関するコマンド

git init

リポジトリの作成

git init 
git init name
git init --bare
git init --shared

git config

gitリポジトリの設定

git config
git config --global

git add

ファイルをインデックスに登録する

git add file
git add --all

git diff

差分を出力する

git diff
git diff file
git diff commit1 commit2
git diff HEAD
git diff --cached
git diff --cached -M

git log,git shortlog

コミットログの表示

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
git status -s
git status -sb

git mv

ディレクトリ、ファイルの移動、変更を行う

git mv file_before file_after
git mv -f file_before file_after

git rm

ディレクトリ、ファイルの削除を行う

git rm file
git rm --cached file
git rm -r dir

git commit

ローカルリポジトリにコミット

git commit
git commit -m
git commit -a
git commit file
git commit --amend

git reset

ローカルリポジトリ、インデックス、ワーキングツリーをもとに戻す

git reset --hard commit1
git reset --soft commit1
git reset --mixed commit1
git reset --mixed commit1 file

git clean

ワーキングツリーを掃除する

git clean
git clean -n
git clean --dry-run
git clean -f
git clean -fd

git grep

ファイルから文字列を検索する

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

.gitignore

リポジトリで管理しないファイルを設定する

echo 'file' > .gitignore
echo '!file' > .gitignore

git show

コミット内容を表示する

git show
git show commit

リモートリポジトリに関するコマンド

git clone

リモートリポジトリをローカルにコピーする

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

リモートリポジトリの管理、更新を行う

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

ブランチをマージする

git merge branch
git merge --squash branch

git push

リモートリポジトリにローカルリポジトリのデータを送信する

git push remote_repo local_branch:remote_branch
git push remote_repo :remote_branch

git pull

ローカルリポジトリにリモートリポジトリのデータを反映する

git pull remote_repo local_branch
git pull remote_repo
git pull

git branch

ローカルブランチの作成、削除、確認、トラッキング

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

ファイルの特定の行が最後に編集された履歴を追跡する

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

ブランチをインデックスとワーキングコピーに展開する

git checkout branch_name
git checkout branch_name file
git checkout -f
git checkout -b branch_name

git tag

タグをつける

git tag name commit
git tag -m "message" name
git tag -s name
git tag -d name

git describe

最も近いタグを表示する

git describe

git archive

リポジトリのスナップショットを作成する

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 fetch git://xxx.org/xxx.git branch_name

git stash

未コミットの状態を一時的に保存する

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

コミットした内容を取り消す

git revert ':/commit comment'
git revert -n HEAD~4

git rebase

指定したブランチの最新コミットに追従させる

git rebase branch_name
git rebase --continue
git rebase --abort
git rebase --skip
git rebase -i branch_name

git format-patch

コミットをメール形式で出力する

git format-patch -o out_dir/ origin/master

git send-email

パッチをメールで送信する

git send-email --to [email protected] filename.patch
git send-email --to [email protected] out_dir

git am

メールで送られてきたパッチを取り込む

git am patch_dir/*

git request-pull

pull申請用の情報を出力する

git request-pull master git://xxx.org/xxx.git branch_name

git cherry

ブランチに含まれていないコミットを調べる

git cherry -v dist src

git cherry-pick

特定のコミットをブランチに取り込む

git cherry-pick commit

git bisect

バグが入り込んだコミットを特定する

git bisect start commit1 commit2
git bisect good
git bisect bad
git bisect reset
git bisect run make

git show-branch

ブランチの状態を表示する

git show-branch

git submodule

他のリポジトリをモジュールとして利用する

git submodule add git://xxx.org/xxx.git
git submodule status
git submodule init
git submodule update

git gc

リポジトリのオブジェクトを掃除する

最終更新:2012年04月17日 20:21
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。