「.NET 開発基盤部会 Wiki」は、「Open棟梁Project」,「OSSコンソーシアム .NET開発基盤部会」によって運営されています。
目次 †
概要 †
Gitコマンドの覚書
用語 †
repository †
- ファイルやディレクトリの変更履歴を記録して管理する場所。
- 管理対象のファイルやディレクトリはrepositoryの下に置く。
http://www.backlog.jp/git-guide/intro/intro1_2.html
local / remote †
- remote repository
- サーバに配置して複数人で共有するためのrepository。
- local repository
- ユーザ一人が利用する、自分の手元のマシン上に配置するrepository。
- local repositoryの内容はremote repositoryを経由して公開・取得する。
http://www.backlog.jp/git-guide/intro/intro1_3.html
bare / non-bare †
- non-bare repository
ワーキングディレクトリを持つ。
- bare repository
ワーキングディレクトリを持たない。更新情報だけを持っている。
http://www.nekotricolor.com/entry/theory-of-bare-and-non-bare-repository-manage-wordpress-themes-with-git
branch †
http://www.backlog.jp/git-guide/stepup/stepup1_1.html
branch名 †
- (remote)/(branch)
remoteのrepositoryのbranch
- (origin)/(branch)
cloneしたremoteのrepositoryのbranch
HEAD †
現在使用しているbranchの先頭を表す名前
stash †
ファイルの変更内容を一時的に記録しておく領域。
commit †
ファイルやディレクトリの追加・変更を、Repositoryに記録する
branch †
branch †
branchする
- command
- 現在のbranchから<new-branch>をbranchする
git branch <new-branch>
checkout †
branchをcheckoutする(切り替える)。
- command
- 既存branch <existing-branch> に切り替える。
git checkout <existing-branch>
- 新規branch <new-branch> を作成して即時checkout
git checkout -b <new-branch>
- 既存branch <existing-branch>から新規branch <new-branch> を作成して即時checkout
git checkout -b <new-branch> <existing-branch>
merge †
branchをmergeする。
削除 †
branchを削除する。
repository †
clone †
git clone は既存の git repositoryのclone (コピー) を作成する
repository間 †
git remote †
git fetch †
remote repositoryからfetchする。
git pull †
remote repositoryからpull(fetch & merge)する。
git push †
remote repositoryへpushする。
ステージングの操作 †
git add †
ステージング・エリアにaddする。
- command
- <file> に加えられたすべての変更をステージして次回のコミットの対象とする。
git add <file>
- <directory> 内のすべての変更をステージして次回のコミットの対象とする。
git add <directory>
- インタラクティブなステージングセッションを開始する。
git add -p
git clean †
ステージング・エリアからcleanする。
- command
- git clean の「予行演習」を行うコマンドで削除されるファイルを表示する。
git clean -n
- 追跡対象外のファイルをカレントディレクトリから削除する。
ただし、.gitignore. で指定したファイルは削除しない。
git clean -f
- 追跡対象外のファイルを指定したパスから削除する。
git clean -f <path>
- 追跡対象外のファイルとディレクトリをカレントディレクトリから削除する。
git clean -df
- 追跡対象外ファイルと通常無視されるファイルをカレントディレクトリから削除する。
git clean -xf
git reset †
commitのreset
- command
- 作業ディレクトリに変更も加えずに、指定したファイルをステージングエリアから削除する
git reset <file>
- 作業ディレクトリに何の変更も加えることなくステージエリアをresetして直前のcommit時の状態と一致させる
git reset
- ステージエリアと作業ディレクトリをresetして直前のcommit時の状態と一致させる
git reset --hard
commitの操作 †
<commit> = commit の"SHA-1 id"
git commit †
変更のcommit
git revert †
commitのrevert
- command
- 特定のcommitのrevert
git revert <commit>
git reset †
commitのreset
- 現在のbranchの先端を <commit> の位置に戻した上でステージングエリアをその状態と一致するように元に戻すが、作業ディレクトリのみはそのままにしておく。
これにより、変更規模が小さく整理されたスナップショットを作成してlocal repositoryへ再commitできる。
git reset <commit>
確認 †
branch †
git branch †
branchの確認
- command
- local branchの確認
git branch
- remote追跡branchを表示
git branch -r
- local branchとremote追跡branchの両方のbranchを表示
git branch -a
- 名称の変更
git branch -m <branch>
commit †
git log †
logの確認
- command
- commit履歴全体をデフォルトの形式で表示
git log
- 表示するcommit数を <limit> に制限する。
git log -n <limit>
- commit履歴を概観する(各々のcommitの内容を1行に圧縮して表示)
git log --oneline
- 改変されたファイルおよびその中での追加行数と削除行数を増減数で表示
git log --stat
- 各々のcommitに対応するパッチ(commitの完全な差分情報)を表示します。
git log -p
ステージング †
git status †
statusの確認
- command
- ステージされたファイル、されていないファイル、追跡対象外のファイルを一覧表示。
git status