Git ======== {{tag: git}} 分散型バージョン管理システムGit -------- {{TOC 3-}} ### Git とは ### >Git(ぎっと)はプログラムなどのソースコード管理を行う分散型バージョン管理システム。動作速度に重点が置かれている。Linuxカーネルのソースコード管理を目的として、リーナス・トーバルズによって開発された。 << http://ja.wikipedia.org/wiki/Git wikipedia - Git Git は Linux のカーネル開発や Perl コアの開発などで利用されている。 ### Git のダウンロードとインストール ### [[http://git-scm.com/ http://git-scm.com/]] から[[http://git-scm.com/download ダウンロード]]できる。 各ディストリに RPM で用意されているものは少し古いので、こだわりがなければ stable 最新版をソースから入れるのをおすすめする。 また、git help で詳細なマニュアルを参照するには、別途以下のように manpage のインストールが必要
# wget http://www.kernel.org/pub/software/scm/git/git-manpages-1.7.3.2.tar.gz
# tar zxvf git-manpages-1.7.3.2.tar.gz
# cp -r man* /usr/share/man
# rm -rf man*
### リポジトリを作成する ### さっそく、git リポジトリを作成してみる。
$ cd [プロジェクトのディレクトリ]
$ git init
(いくつかのファイルを加えて、編集する)
$ git add .
$ git commit -m 'Initial commit'
### リポジトリをクローンしてくる ### 既存のリポジトリを、手元に持ってくるには、以下のようにする。
$ git clone [リポジトリ]
$ cd [リポジトリのディレクトリ]
ファイルを編集する
$ git add 編集したファイル
$ git commit -m 'コミットメッセージ'
### ヘルプの見方 ### コマンドのうしろに -h を付ければだいたい見れる
$ git init -h
manpage がインストールされていれば、詳細なマニュアルが参照できる。
$ git help init
または、
$ man git-init
### git config ### いろいろ設定しておくと便利。
$ git config -h
.gitconfig
[user]
    name = foo
    email = foo@example.com
[color]
    ui = true
[alias]
    co = checkout
    st = status
    ci = commit -a
    di = diff
    br = branch
    wh = whatchanged
    stat = log --stat --summary
    logg = log --graph --decorate --pretty=format:\"%ad [%cn] <%h> %n %Cgreen%d%Creset %s %n\" --name-status
    logs = log --graph --decorate --pretty=format:\"%ad [%cn] <%h> %n %Cgreen%d%Creset %s %n\" --stat
[core]
    pager = lv -cOu8
    autocrlf = input
### 基本コマンド ### * git init git リポジトリを作成する * git clone git リポジトリをローカルに持ってくる * git add ファイル(ディレクトリ)をインデックスに加える * git commit 手元のリポジトリに変更をコミットする * git pull リポジトリから差分をとってきてマージする * git push リモートリポジトリに差分のupdateを行う ### git の構造 ### git を使う(知る)上で、リポジトリやワーキングコピーやインデックスについて知らないとけっこう困る。 [[http://marklodato.github.com/visual-git-guide/index-en.html こちらのページで図解されている]] ので一読あれ。 ### git clone ### | プロトコル | 指定方法 | ----------------| ------------------------------------------| | rsync | rsync://<ホスト名>/<Gitリポジトリのパス> | | HTTP | http://<ホスト名>[:ポート番号]/<Gitリポジトリのパス> | | HTTPS | https://<ホスト名>[:ポート番号]/<Gitリポジトリのパス> | | git | git://<ホスト名>[:ポート番号]/<Gitリポジトリのパス> | | SSH | ssh://[ユーザー名@]<ホスト名>[:ポート番号]/<Gitリポジトリのパス> | | ローカルファイル | <Gitリポジトリのパス>もしくはfile://<Gitリポジトリのパス> | [表1 Gitで利用できるリポジトリURL] ### git-completion ### TAB で git コマンドやブランチ名を補完してくれる便利な bash ツールが、実は gitのソースアーカイブに含まれている。 1. [[http://git-scm.com/download http://git-scm.com/download]] からアーカイブを落としてくる 1. 解凍する 1. contrib/completion/git-completion.bash を $HOME あたりにおく 1. .bashrc に 「source $HOME/.git-completion.bash」を書いておく ついでに、まとめて以下のように .bashrc を書いておくと、プロンプトにブランチ名を表示することもできて便利。
if [ -f ~/.git-completion.bash ]; then
    source ~/.git-completion.bash
    if [ -r "$HOME/.git-completion.bash" ]; then # = git-completion.bash
        PS1="[\u@\h\$(__git_ps1 \" %s \")\w]\\$ "
    else
        PS1="[\u@\h \w]\\$ "
    fi
fi