SYNOPSIS

git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate|--no-pager] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] コマンド [引数]

解説

git は高速で、拡張性のある、分散型のリビジョン管理システムです。 非常に豊富なコマンドセットを持ち、高レベルな操作と内部への完全なアクセスの 両方が可能です。

始めは gittutorial(7) と便利なコマンドの最少セットを 解説している 日々の git の利用 を参照してください。 各コマンドのドキュメントは "man git-コマンド名" から得られます。 CVS ユーザは gitcvs-migration(7) も参考になるかもしれません。 より深い導入として git ユーザマニュアル があります。

コマンド は git コマンド(下記参照)の名前または 設定ファイル(git-config(1)参照)内で定義された別名です。

整形されたハイパーリンク付きの git の最新のドキュメントは 以下の場所で参照できます。 http://www.kernel.org/pub/software/scm/git/docs/

オプション

--version

コールされている git プログラムのバージョンを表示します。

--help

概要とよく利用されるコマンドの一覧を表示します。 --all または -a オプションを付けた場合は 全コマンドの一覧を表示します。git コマンドがこのオプション付きで 呼ばれた場合、そのコマンドのマニュアルページを呼び出します。

マニュアルページの表示方法をコントロールするオプションは他にもあります。 詳細は git-help(1) を参照してください。 git --help … は内部的には git help … に置き換えられます。

--exec-path

gitの中核(core git)プログラムがインストールされているパスを指定します。 環境変数 GIT_EXEC_PATH を設定することでも指定可能です。 パスの指定がない場合、git は現在設定されているパスを表示して終了します。

--html-path

gitのHTMLドキュメントがインストールされているパスを表示して終了します。

-p
--paginate

全ての出力を less (または設定されていれば $PAGER) にパイプ接続します。

--no-pager

git の出力をページャにパイプ接続しないようにします。

--git-dir=<path>

リポジトリのパスを設定します。この設定は環境変数 GIT_DIR にて指定することも できます。値には絶対パス、または現在の作業ディレクトリからの相対パスが 指定可能です。

--work-tree=<path>

作業ツリーのパスを設定します。 この値はコマンド実行時に自動的に検出される .git ディレクトリ内の リポジトリとは組み合わせて利用されません。(この値は $GIT_DIR または --git-dir が設定されている時のみ利用できます) この設定は環境変数 GIT_WORK_TREE または構成変数 core.worktree にて 指定することもできます。値には絶対パスまたは --git-dir または GIT_DIR により指定されるディレクトリからの相対パスを 指定することができます。 注意:--git-dir または GIT_DIR が指定されているが、--work-tree , GIT_WORK_TREE, core.worktree が指定されていない場合、 現在の作業ディレクトリが作業ツリーのトップディレクトリとして 扱われます。

--bare

リポジトリを裸の(bare)リポジトリとして扱います 変数 GIT_DIR が設定されていない場合、現在の作業ディレクトリ が設定されます。

さらに進んだドキュメント

git を使い始めるには上述のリファレンスを見てください。 以下は初めてのユーザにはおそらく詳しすぎます。

ユーザマニュアルの git のコンセプトgitcore-tutorial(7) は git のアーキテクチャについてのイントロです。

howto には役に立つ使用例がいくつか 紹介されています。

内部構造は GIT API documentation で説明されています。

git のコマンド

git は高レベルなコマンド("磁器"(porcelain))と下位レベルのコマンド ("配管"(plumbing))に分けられます。

高レベルなコマンド("磁器"(porcelain))

磁器(porcelain)のコマンドは主要コマンドとユーザ補助コマンドに 分けられます。

主要な磁器(porcelain)コマンド

git-add(1)

Add file contents to the index.

git-am(1)

Apply a series of patches from a mailbox.

git-archive(1)

Create an archive of files from a named tree.

git-bisect(1)

Find by binary search the change that introduced a bug.

git-branch(1)

List, create, or delete branches.

git-bundle(1)

Move objects and refs by archive.

git-checkout(1)

Checkout a branch or paths to the working tree.

git-cherry-pick(1)

Apply the change introduced by an existing commit.

git-citool(1)

Graphical alternative to git-commit.

git-clean(1)

Remove untracked files from the working tree.

git-clone(1)

Clone a repository into a new directory.

git-commit(1)

Record changes to the repository.

git-describe(1)

Show the most recent tag that is reachable from a commit.

git-diff(1)

Show changes between commits, commit and working tree, etc.

git-fetch(1)

Download objects and refs from another repository.

git-format-patch(1)

Prepare patches for e-mail submission.

git-gc(1)

Cleanup unnecessary files and optimize the local repository.

git-grep(1)

Print lines matching a pattern.

git-gui(1)

A portable graphical interface to Git.

git-init(1)

Create an empty git repository or reinitialize an existing one.

git-log(1)

Show commit logs.

git-merge(1)

Join two or more development histories together.

git-mv(1)

Move or rename a file, a directory, or a symlink.

git-pull(1)

Fetch from and merge with another repository or a local branch.

git-push(1)

Update remote refs along with associated objects.

git-rebase(1)

Forward-port local commits to the updated upstream head.

git-reset(1)

Reset current HEAD to the specified state.

git-revert(1)

Revert an existing commit.

git-rm(1)

Remove files from the working tree and from the index.

git-shortlog(1)

Summarize git-log output.

git-show(1)

Show various types of objects.

git-stash(1)

Stash the changes in a dirty working directory away.

git-status(1)

Show the working tree status.

git-submodule(1)

Initialize, update or inspect submodules.

git-tag(1)

Create, list, delete or verify a tag object signed with GPG.

gitk(1)

The git repository browser.

補助コマンド

操縦者(Manipulators):

git-config(1)

Get and set repository or global options.

git-fast-export(1)

Git data exporter.

git-fast-import(1)

Backend for fast Git data importers.

git-filter-branch(1)

Rewrite branches.

git-lost-found(1)

(deprecated) Recover lost refs that luckily have not yet been pruned.

git-mergetool(1)

Run merge conflict resolution tools to resolve merge conflicts.

git-pack-refs(1)

Pack heads and tags for efficient repository access.

git-prune(1)

Prune all unreachable objects from the object database.

git-reflog(1)

Manage reflog information.

git-relink(1)

Hardlink common objects in local repositories.

git-remote(1)

manage set of tracked repositories.

git-repack(1)

Pack unpacked objects in a repository.

git-repo-config(1)

(deprecated) Get and set repository or global options.

質問者(Interrogators):

git-annotate(1)

Annotate file lines with commit information.

git-blame(1)

Show what revision and author last modified each line of a file.

git-cherry(1)

Find commits not merged upstream.

git-count-objects(1)

Count unpacked number of objects and their disk consumption.

git-difftool(1)

Show changes using common diff tools.

git-fsck(1)

Verifies the connectivity and validity of the objects in the database.

git-get-tar-commit-id(1)

Extract commit ID from an archive created using git-archive.

git-help(1)

display help information about git.

git-instaweb(1)

Instantly browse your working repository in gitweb.

git-merge-tree(1)

Show three-way merge without touching index.

git-rerere(1)

Reuse recorded resolution of conflicted merges.

git-rev-parse(1)

Pick out and massage parameters.

git-show-branch(1)

Show branches and their commits.

git-verify-tag(1)

Check the GPG signature of tags.

git-whatchanged(1)

Show logs with difference each commit introduces.

他者との相互作用

これらのコマンドは外部のSCMや他者からのe-mailパッチと 相互作用することができます。

git-archimport(1)

Import an Arch repository into git.

git-cvsexportcommit(1)

Export a single commit to a CVS checkout.

git-cvsimport(1)

Salvage your data out of another SCM people love to hate.

git-cvsserver(1)

A CVS server emulator for git.

git-imap-send(1)

Send a collection of patches from stdin to an IMAP folder.

git-quiltimport(1)

Applies a quilt patchset onto the current branch.

git-request-pull(1)

Generates a summary of pending changes.

git-send-email(1)

Send a collection of patches as emails.

git-svn(1)

Bidirectional operation between a single Subversion branch and git.

下位レベルのコマンド ("配管"(plumbing))

git はそれ自体に磁気(porcelain)の階層を含んでいますが、 その下位レベルコマンドは代替の磁器を開発するのに十分役に立ちます。 磁器の開発者は git-update-index(1)git-read-tree(1) から読み始めると良いでしょう。

これら下位レベルコマンドのインターフェース(入力、出力、 オプションとその意味)は、これらコマンドがスクリプト化して 使用される為、磁器レベルのコマンドよりもずっと安定性が 求められます。一方、磁器コマンドのインターフェースは エンドユーザの経験に基づく改良の為、変更されていく必要があります。

以下の記述では下位レベルコマンドを以下の3つに分割します。 1.リポジトリ、インデックス、作業ツリー内のオブジェクトを 操作するコマンド。 2.質問し、オブジェクトを比較するコマンド。 3.リポジトリ間でオブジェクトと参照を移動するコマンド。

操作コマンド

git-apply(1)

Apply a patch on a git index file and a working tree.

git-checkout-index(1)

Copy files from the index to the working tree.

git-commit-tree(1)

Create a new commit object.

git-hash-object(1)

Compute object ID and optionally creates a blob from a file.

git-index-pack(1)

Build pack index file for an existing packed archive.

git-merge-file(1)

Run a three-way file merge.

git-merge-index(1)

Run a merge for files needing merging.

git-mktag(1)

Creates a tag object.

git-mktree(1)

Build a tree-object from ls-tree formatted text.

git-pack-objects(1)

Create a packed archive of objects.

git-prune-packed(1)

Remove extra objects that are already in pack files.

git-read-tree(1)

Reads tree information into the index.

git-symbolic-ref(1)

Read and modify symbolic refs.

git-unpack-objects(1)

Unpack objects from a packed archive.

git-update-index(1)

Register file contents in the working tree to the index.

git-update-ref(1)

Update the object name stored in a ref safely.

git-write-tree(1)

Create a tree object from the current index.

質問コマンド

git-cat-file(1)

Provide content or type and size information for repository objects.

git-diff-files(1)

Compares files in the working tree and the index.

git-diff-index(1)

Compares content and mode of blobs between the index and repository.

git-diff-tree(1)

Compares the content and mode of blobs found via two tree objects.

git-for-each-ref(1)

Output information on each ref.

git-ls-files(1)

Show information about files in the index and the working tree.

git-ls-remote(1)

List references in a remote repository.

git-ls-tree(1)

List the contents of a tree object.

git-merge-base(1)

Find as good common ancestors as possible for a merge.

git-name-rev(1)

Find symbolic names for given revs.

git-pack-redundant(1)

Find redundant pack files.

git-rev-list(1)

Lists commit objects in reverse chronological order.

git-show-index(1)

Show packed archive index.

git-show-ref(1)

List references in a local repository.

git-tar-tree(1)

(deprecated) Create a tar archive of the files in the named tree object.

git-unpack-file(1)

Creates a temporary file with a blob's contents.

git-var(1)

Show a git logical variable.

git-verify-pack(1)

Validate packed git archive files.

一般に、質問コマンドは作業ツリー内のファイルを変更することは ありません。

リポジトリの同期

git-daemon(1)

A really simple server for git repositories.

git-fetch-pack(1)

Receive missing objects from another repository.

git-send-pack(1)

Push objects over git protocol to another repository.

git-update-server-info(1)

Update auxiliary info file to help dumb servers.

以下は上記コマンドにより使用されるヘルパープログラムです; エンドユーザは通常これらを直接使用することはありません。

git-http-fetch(1)

Download from a remote git repository via HTTP.

git-http-push(1)

Push objects over HTTP/DAV to another repository.

git-parse-remote(1)

Routines to help parsing remote repository access parameters.

git-receive-pack(1)

Receive what is pushed into the repository.

git-shell(1)

Restricted login shell for GIT-only SSH access.

git-upload-archive(1)

Send archive back to git-archive.

git-upload-pack(1)

Send objects packed back to git-fetch-pack.

内部ヘルパーコマンド

これらは他のコマンドにより使用される内部ヘルパーコマンドです; エンドユーザは通常これらを直接使用することはありません。

git-check-attr(1)

Display gitattributes information.

git-check-ref-format(1)

Ensures that a reference name is well formed.

git-fmt-merge-msg(1)

Produce a merge commit message.

git-mailinfo(1)

Extracts patch and authorship from a single e-mail message.

git-mailsplit(1)

Simple UNIX mbox splitter program.

git-merge-one-file(1)

The standard helper program to use with git-merge-index.

git-patch-id(1)

Compute unique ID for a patch.

git-peek-remote(1)

(deprecated) List the references in a remote repository.

git-sh-setup(1)

Common git shell script setup code.

git-stripspace(1)

Filter out empty lines.

構成機構

0.99.9 (実際は0.99.8.GITの途中)から、 各リポジトリの構成オプションを保持する目的で .git/config ファイルが使用されるようになりました。 その形式は単純なテキストファイルであり、一部の人には .ini 形式として馴染みのあるものです。

様々なコマンドが構成ファイルを読み込んで、 コマンドの動作を調整します。

識別用語

<object>

任意のオブジェクトの型に対して、オブジェクトの名前を指し示します。

<blob>

blob オブジェクトの名前を指し示します。

<tree>

ツリーオブジェクトの名前を指し示します。

<commit>

コミットオブジェクトの名前を指し示します。

<tree-ish>

ツリー、コミットまたはタグオブジェクトの名前を指し示します。 <tree-ish> の引数を取るコマンドは、最終的には <tree> オブジェクト に対して作用しますが、<tree> を指し示す <commit> と <tag> オブジェクトを引数に指定することも可能です。

<commit-ish>

コミットまたはタグオブジェクトの名前を指し示します。 <commit-ish> の引数を取るコマンドは、最終的には <commit> オブジェクトに対して作用しますが、<commit> を指し示す <tag> オブジェクトを引数に指定することも可能です。

<type>

オブジェクトタイプが必要であることを示します。 一般に blob, tree, commit, または tag のどれかです。

<file>

ファイル名を指し示します。- 通常は GIT_INDEX_FILE が表す ツリー構造のルートからの相対パスです。

シンボリックな識別子

任意の <object> を引数に持つすべての git コマンドにて 以下のシンボリックな識別子を使用することができます。

HEAD

現在のブランチの head を指し示します。 (つまり、$GIT_DIR/HEAD の内容を指し示します)

<tag>

正しいタグの '名前'。 (つまり、$GIT_DIR/refs/tags/<tag> の内容)

<head>

正しい head の '名前'。 (つまり、$GIT_DIR/refs/heads/<tag> の内容)

オブジェクトの名前を表す方法のより完全な一覧は git-rev-parse(1) 内の"リビジョンの指定方法" の節を 参照してください。

ファイル/ディレクトリの構造

gitrepository-layout(5) のドキュメントを 参照してください。

各フックの詳細は githooks(5) を参照してください。

より高レベルなSCMにより $GIT_DIR 内の追加情報の提供と管理が 可能になるでしょう。

用語

gitglossary(7) のドキュメントを参照してください。

環境変数

様々な git コマンドが以下の環境変数を参照しています。

git リポジトリ

これらの環境変数は 全ての 中核となる git コマンドに適用されます。 Nb: これらの値をgit の上位に位置する SCMS によって利用/上書きする ことは何の価値もないので、Cogit などを利用する場合は注意してくだ さい。

GIT_INDEX_FILE

この環境変数は代替インデックスファイルを指定します。 定義されていない場合、デフォルトでは $GIT_DIR/index が 使用されます。

GIT_OBJECT_DIRECTORY

オブジェクトの格納ディレクトリがこの環境変数により指定されていた場合、 sha1 ディレクトリはこの下に作成されます。- 定義されていない場合、 デフォルトでは $GIT_DIR/objects ディレクトリが使用されます。

GIT_ALTERNATE_OBJECT_DIRECTORIES

git オブジェクトの不変性により、古いオブジェクトは 共有化された参照のみのディレクトリにアーカイブさせることが できます。この値に ":" を区切り文字(Windowsでは";")とした git オブジェクトの ディレクトリの一覧を指定子、git オブジェクトを検索する際に 使用させることができます。新しいオブジェクトはこれらの ディレクトリには書き込まれません。

GIT_DIR

環境変数 GIT_DIR が設定されていた場合、 デフォルトである .git の代わりに、この値がリポジトリへのパス として使用されます。

GIT_WORK_TREE

作業ツリーのパスを設定します。 この値はコマンド実行時に自動的に検出される .git ディレクトリ内の リポジトリとは組み合わせて利用されません。(この値は $GIT_DIR または --git-dir が設定されている時のみ利用できます) この設定はコマンドラインオプション --work-tree または 構成変数 core.worktree にて指定することもできます。

GIT_CEILING_DIRECTORIES

これはコロンで区切られた絶対パスのリストです。 この変数を設定すると、gitは設定したディレクトリよりも 上のディレクトリからレポジトリディレクトリを探しません。 カレントディレクトリやコマンドラインか環境変数で設定した GIT_DIR は排除しません。 (読み込みの遅いネットワークパスを除外するのに便利です)

git コミット

GIT_AUTHOR_NAME
GIT_AUTHOR_EMAIL
GIT_AUTHOR_DATE
GIT_COMMITTER_NAME
GIT_COMMITTER_EMAIL
GIT_COMMITTER_DATE
EMAIL

git-commit-tree(1) を参照

git 差分表示

GIT_DIFF_OPTS

この変数に設定できる正しい値は "--unified=??" または "-u??" のみです。この指定により unified diff が行われる時に表示する コンテキスト(変更前後の)行数を指定できます。 この指定は git diff コマンドの実行時に指定する "-U" または "--unified" オプションよりも優先して使用されます。

GIT_EXTERNAL_DIFF

環境変数 GIT_EXTERNAL_DIFF が設定されている場合、 上述の diff が実行される代わりに、ここで指定されているプログラム が呼び出されます。追加、削除、変更されたパスに対して GIT_EXTERNAL_DIFF が7つのパラメータとともに呼び出されます:

パス 古いファイル 古いhex 古いモード 新しいファイル 新しいhex 新しいモード

各パラメータの説明:

<古い|新しい>ファイル GIT_EXTERNAL_DIFF が <古い|新しい>ファイルの中身を 読み込む為のファイル名
<古い|新しい>hex 40桁の16進の SHA1 ハッシュ値、
<古い|新しい>hex ファイルモードの8進数表現。

ファイルパラメータはユーザの作業ファイル(例えば、"git-diff-files" 内の 新しいファイル)、/dev/null (例えば、新しいファイルが追加された 時の 古いファイル)、または一時ファイル(例えば、索引内の 古いファイル) を指し示すこともあります。GIT_EXTERNAL_DIFF は一時ファイルを削除 することに気を使う必要はありません。--- GIT_EXTERNAL_DIFF が終了すると 一時ファイルは削除されます。

マージされなかったパスに対しては GIT_EXTERNAL_DIFF は 1つのパラメータ <path> とともに呼び出されます。

その他

GIT_MERGE_VERBOSITY

再帰的なマージ戦略により表示される出力の合計値を 管理するための数値です。merge.verbosity を上書きします。 git-merge(1) 参照。

GIT_PAGER

この環境変数は $PAGER を上書きします。 これを空文字または "cat" に指定すると、git はページャを 起動しません。 core.pager オプションについてはgit-config(1) 参照して下さい.

GIT_SSH

この環境変数が設定されていた場合、git-fetchgit-push はリモートシステムに接続する必要があった 時に、ssh の代わりにこのコマンドを使用します。 $GIT_SSH コマンドには必ず2つの引数が渡されます: その URL の username@host(あるいは単に host)と、 そのリモートシステム上で実行するシェルコマンドです。

GIT_SSH 内でリストしたいプログラムにオプションを渡したい時は、 プログラムをラップしてシェルスクリプトにオプションを渡し、 GIT_SSHがそのシェルスクリプトを参照するように設定する必要があります。

通常は .ssh/config ファイルにて望ましいオプションを設定した方が 容易です。より詳細は ssh のドキュメントを参照してください。

GIT_FLUSH

この環境変数が "1" に設定されている場合、 git-blame(インクリメンタルモード)、git-rev-list, git-log, そして git-whatchanged などのコマンドが呼ばれた時に、各コミットの境界レコードが フラッシュされた後に出力ストリームが強制的にフラッシュされます。 この変数が "0" に設定されていた場合、これらコマンドの出力は 完全に I/O がバッファリングされます。この環境変数が 設定されていない場合、git は標準出力がファイルにリダイレクト されているかどうかによってバッファリングされるかれレコードの境界で フラッシュされるかが決定されます。

GIT_TRACE

この変数が "1", "2" または "true" (大文字小文字を区別します) に設定されていた場合、git は trace: のメッセージを標準エラーに出力し、 エイリアスの展開、実行される built-in コマンド、外部コマンド実行 について説明します。 この値が 1 より大きく10より小さい整数が指定された場合、 git はこの値をファイル識別子として解釈し、このファイル識別子 にトレースメッセージを書き込もうとします。 代わりに、この値が絶対パスが指定されていた場合('/'の文字から始まる 場合)、git はこれをファイルパスとして解釈し、トレースメッセージを そこに書き込もうとします。

議論

以下の詳細は ユーザマニュアル内の Gitのコンセプトの章gitcore-tutorial(7) から得ることができます。

git のプロジェクトは通常、最上位に ".git" のサブディレクトリを持つ 作業ディレクトリから構成されています。.git ディレクトリには プロジェクトの完全な履歴を表現した圧縮されたオブジェクトDB、 作業ツリーの現在の中身の履歴にリンクした "索引(index)"ファイル、 そして tag や ブランチの head のような履歴を指し示す名前付きポインタ とを含んでいます。

オブジェクトDBは主に3つのタイプのオブジェクトを含んでいます: blob はファイルのデータを保持し;tree は blob と他の tree を 指し示してディレクトリ階層を構成し;commit は1つの tree と 複数の親の commit を参照しています。

commit は他のシステムで言われる "チェンジセット" や "バージョン" と等しく、プロジェクトの履歴の1ステップを表現し、 その親は直接1つ前のステップを表現します。 複数の親を持つコミットは独立した開発ラインのマージを表現します。

全てのオブジェクトはその中身の SHA1 ハッシュによって名前が付けられ、 通常 40 の16進数で書かれます。この名前は大局的にユニークです。 ある commit につながる全ての履歴は、ちょうどそのコミットのサインにより 保証されています。4番目のオブジェクトタイプ tag はこの目的の為に 与えられています。

オブジェクトは初めに作成されると個々のファイルに格納されますが、 効率性の為、後に "pack ファイル"として一緒に圧縮されます。

refs と呼ばれる名前付けされたポインタは履歴内の注目したい位置に 目印を付けます。ref はオブジェクトの SHA1名または他の ref の名前が 保管されています。名前が ref/head/ で始まる ref は開発中のブランチの 最新のコミット("head")の SHA1名が保管されています。tag のSHA1名は ref/tags/ の下に保管されています。HEAD という名前の特別な ref には 現在チェックアウトしているブランチの名前が保管されています。

索引(index)ファイルは全てのパスの一覧で初期化されており、 それぞれのパス、blobオブジェクト、属性の集合を含んでいます。 blobオブジェクトは現在のブランチ head のファイルの中身を表現しています。 属性(採集更新日時、サイズなど)は作業ツリー内の対応するファイルから 取得されます。作業ツリーにて追加した変更はこれらの属性と比較することに より検出されます。索引は新しいコンテンツにより更新され、新しいコミット は索引内に格納されているコンテンツから作成されます。

索引は同一パス名の複数のエントリ("ステージ"と呼びます)を格納する こともできます。これらステージはマージ作業中の様々な未マージのバージョンを 保持する目的で利用されます。

著者

文書化

git スイートにたいする文書化は David Greaves <david@dgreaves.com> によって着手され、後に git-list <git@vger.kernel.org> 上の貢献者によって 強化されました。

参考

gittutorial(7), gittutorial-2(7), Everyday Git, gitcvs-migration(7), gitglossary(7), gitcore-tutorial(7), gitcli(7), The Git User's Manual

GIT

git(1) スイートの一部