SlideShare una empresa de Scribd logo
1 de 85
Git - 実践入門編 (一般公開用)

    2012/04/23, DT Corp
     Naomichi Yamakita
初めに
本資料の役割


-       今後始まる新しいプロジェクトは全てGitで運営します

    -    既存プロジェクトに関しては移行しません(一部を除く)

-       本資料はGit利用者(開発者)を対象とした実践向きの内容となってます

    -    プロジェクトを運用する上で、必要最低限の機能を紹介します

    -    資料に記載されている内容は確実に理解して下さい

    -    質問があればその場で挙手して下さい

-       CUIベースで説明を進めます

    -    GUIツール(WindowsのTortoseGit等)の使い方については触れません
アジェンダ


-   初めに

-   Gitの概要

-   重要キーワードを理解する

-   実践チュートリアル

-   トラブルシューティング

-   終わりに
Gitの概要
今までのバージョン管理体制 <Subversion>


-       集中型バージョン管理システム

    -    サーバ上に中央リポジトリを持つ

    -    各開発者はサーバからリソースをチェックアウト・コミットすることで
         開発を進めていく

    -    コミットしたら即中央リポジトリに反映される

    -    履歴の確認、コミット、ブランチの切り替え等はその都度サーバにアク
         セスする必要がある
新しいバージョン管理体制 <Git>


-       分散型バージョン管理システム

    -    各開発者がローカルリポジトリを持つ

    -    開発者はローカルリポジトリに変更をコミットし、「プッシュ」を利用
         してネットワーク上のリポジトリに更新を反映する

    -    ローカルリポジトリはリモートリポジトリ上の全ての更新履歴、ファイ
         ル・ディレクトリをミラーリングする

    -    コミット時にスナップショットを保持する(Subversionは差分を保持)

-       Gitは分散型であるため、「中央サーバ」という概念はない

    -    ただしネットワーク上の特定のリモートリポジトリを中央サーバ
         (origin)として見立てることは可能
運用ルールの比較
リビジョンの管理


-       Gitは分散型であるため、リビジョンIDは存在しない

    -    各開発者のリポジトリで更新が行われるため、「最新のリビジョン」が
         ない

    -    コミット単位で40bitのハッシュ値(SHA-1)が振られる

         $ git log --pretty="%h %ai %s"
         75e3e7b15a6635bc050d... 2012-04-17 00:37:51 +0900 second commit
         697d7ace00a7d0432e7d... 2012-04-17 00:01:58 +0900 first commit
リビジョンの管理


-       Gitは分散型であるため、リビジョンIDは存在しない

    -    各開発者のリポジトリで更新が行われるため、「最新のリビジョン」が
         ない

    -    コミット単位で40bitのハッシュ値(SHA-1)が振られる

         $ git log --pretty="%h %ai %s"
         75e3e7b15a6635bc050d... 2012-04-17 00:37:51 +0900 second commit
         697d7ace00a7d0432e7d... 2012-04-17 00:01:58 +0900 first commit


                        コミット時のハッシュ値
Gitのメリット


-       リポジトリ情報をローカルに持つ

    -    変更履歴の確認やブランチの切り替えでネットワークを参照しないため
         高速に動作する

    -    必ずしもリモートリポジトリを持つ必要がない

    -    いつでもどこでもコミットができる

    -    中央リポジトリサーバがダウンしても復旧が容易

-       ブランチの作成が容易かつ高速

    -    Subversionより気軽にブランチを切ったりマージすることができる
Gitのデメリット


-       Subversionに比べ敷居が高い

    -        操作が多く、使用するコマンドも多い

         -    コマンドラインが基本。GUIツールでは全て対応できない

    -        分散型モデルを理解するまで時間がかかる

-       リビジョンIDの概念がないため、最新版を把握しにくい

-       空ディレクトリを管理できない

    -        慣例的に.gitignoreファイルを設置しておく

-       自由度が高いため、チームで利用する場合は運用ルールを決めないと使いに
        くい
Gitを導入する理由


-       Subversionに続くデファクトスタンダード

    -        SubversionからGitに移行したプロジェクト例

         -    Linux Kernel

         -    Ruby on Rails

         -    Perl5

         -    Android

-       GitHubの存在

    -        Gitリポジトリのホスティングサービスを提供

    -        Gitで提供されるOSSが増えてきている
GItのセットアップ 1/3


-       Windows

    -     TortoiseGit + msysgit

    -     http://dtx.co.jp/archives/475

-       Mac

    -     brew install git(またはXcodeのインストール)

-       Linux

    -     yum install git-core
GItのセットアップ 2/3


-   Gitインストール後にコミット時に使用する名前、メールアドレスを登録する
GItのセットアップ 2/3


-   Gitインストール後にコミット時に使用する名前、メールアドレスを登録する




        Name: {your_name}
        Email: {your_email}
GItのセットアップ 3/3


-   開発サーバ上でも同じ設定を登録しておく

     $ git config user.name "{your_name}"
     $ git config user.email {your_email}
     $ cat ~/.gitconfig
     [user]
         name = {your_name}
         email = {your_email}
     [mergetool]
         keepBackup = true
     [core]
         editor = /usr/bin/vim
         quotepath = false
GItのセットアップ 3/3


-   開発サーバ上でも同じ設定を登録しておく

     $ git config user.name "{your_name}"
     $ git config user.email {your_email}
     $ cat ~/.gitconfig
     [user]
         name = {your_name}
         email = {your_email}
     [mergetool]
         keepBackup = true
     [core]                             設定ファイルに名前とメールアドレスが
         editor = /usr/bin/vim            登録されていることが分かる
         quotepath = false
重要キーワードを理解する
リポジトリ


-       ローカルリポジトリ

    -    開発者のマシンに作成されたローカルリポジトリ。開発者はローカルリ
         ポジトリに対し、addやcommitを行う

-       リモートリポジトリ

    -    ネットワーク越しにあるマシン上(サーバとは限らない)のリポジト
         リ。開発者はローカルリポジトリの内容をpushして送信したり、pullで
         ローカルとの差分を取得・マージする

    -    概念的にはSubversionのcommit、updateに近い
ブランチ


-       ローカルブランチ

         -    ローカルリポジトリで管理されるブランチ。git initで新しいリポジト
              リを作成した場合、デフォルトのブランチ名はmasterとなる。
              masterには常に最新のソースをコミットする。Subversionで言うと
              ころのtrunkと似ている

-       リモートブランチ

    -        リモートリポジトリ上のブランチ。git clone時はmasterブランチが
             チェックアウトされる

-       リモートトラッキングブランチ(追跡ブランチ)

    -        現在有効なリモートブランチと繋がりを持つローカルブランチ
HEAD


-       現在作業しているローカルブランチへのポインタ

    -        現在のブランチにおける1つ手前のコミット状態

         -    HEAD^

    -        現在のブランチにおける2つ前のコミット状態

         -    HEAD^^
インデックス 1/2


-       次のコミット対象となるファイルの一時領域

-       新規作成したファイルは必ずインデックスに登録が必要

    -        git add {file_name}

-       ファイルを更新(変更・削除・リネーム等)した場合もインデックスへの再
        登録が必要

    -        2回目以降はコミットと同時にadd指定することも可能

         -     git commit -m {commit_message} -a {file_name}

-       インデックスに登録された状態を「ステージ」と言う
インデックス 2/2


-       インデックスはSubversionにはない考え方

-       インデックスは何のためにあるのか?

    -    次回のコミットに含めたくないファイルを除外することができる
その他


-       ワーキングツリー

    -    ローカルリポジトリにおける実際の作業場所。Subversionの「ワーキン
         グコピー」と同じ

-       コミット

    -    ローカルリポジトリへの更新の反映

    -    スナップショットが作成されるタイミング

-       プッシュ

    -    ローカルリポジトリの内容をリモートリポジトリに反映する

-       プル

    -    リモートリポジトリの内容をローカルリポジトリに反映する
実践チュートリアル
リポジトリを作成する <git init> 1/2


-   新規リポジトリの作成

     $ git init gitrep
     Initialized empty Git repository in /Users/naomichi/
     gitrep/.git/
     $ cd gitrep/
     $ ls -la
     total 0
     drwxr-xr-x   3 naomichi staff    102 4 16 23:21:44 2012 .
     drwxr-xr-x+ 41 naomichi staff 1394 4 16 23:21:44 2012 ..
     drwxr-xr-x 10 naomichi staff     340 4 16 23:21:44 2012 .git
リポジトリを作成する <git init> 1/2


-   新規リポジトリの作成

     $ git init gitrep
     Initialized empty Git repository in /Users/naomichi/
     gitrep/.git/
     $ cd gitrep/
     $ ls -la
     total 0
     drwxr-xr-x   3 naomichi staff    102 4 16 23:21:44 2012 .
     drwxr-xr-x+ 41 naomichi staff 1394 4 16 23:21:44 2012 ..
     drwxr-xr-x 10 naomichi staff     340 4 16 23:21:44 2012 .git



                              .gitはルートディレクトリのみに作成さ
                              れる。.gitはGitのメタ情報を管理する
リポジトリを作成する <git clone> 2/2


-   リモートリポジトリのクローンを作成

     $ git clone git@{fqdn}:test gitrep
     Cloning into gitrep...
     remote: Counting objects: 79, done.
     remote: Compressing objects: 100% (44/44), done.
     remote: Total 79 (delta 4), reused 0 (delta 0)
     Receiving objects: 100% (79/79), 6.09 KiB, done.
     Resolving deltas: 100% (4/4), done.

     [naomichi: workgit]$ ls -la gitrep/
     total 0
     drwxr-xr-x   3 naomichi staff    102   4 16 23:21:44 2012 .
     drwxr-xr-x+ 41 naomichi staff 1394     4 16 23:21:44 2012 ..
     drwxr-xr-x 10 naomichi staff     340   4 16 23:21:44 2012 .git
リポジトリを作成する <git clone> 2/2


-   リモートリポジトリのクローンを作成

       $ git clone git@{fqdn}:test gitrep
       Cloning into gitrep...
       remote: Counting objects: 79, done.
       remote: Compressing objects: 100% (44/44), done.
       remote: Total 79 (delta 4), reused 0 (delta 0)
       Receiving objects: 100% (79/79), 6.09 KiB, done.
       Resolving deltas: 100% (4/4), done.

        [naomichi: workgit]$ ls -la gitrep/
    git clone {repository_path}:{url} {create_directory}
        total 0
        drwxr-xr-x      3 naomichi staff          102 4 16 23:21:44 2012 .
        drwxr-xr-x+ 41 naomichi staff 1394 4 16 23:21:44 2012 ..
        drwxr-xr-x 10 naomichi staff              340 4 16 23:21:44 2012 .git
ファイルをインデックスに登録する <git add>


-   単体ファイルの登録

     $ touch hello
     $ git add hello


-   複数ファイルの登録

     $   mkdir foo
     $   touch foo/bar
     $   touch foo/baz
     $   git add foo



-   全てのファイルを登録

     $ git add .
ファイルをインデックスに登録する <git add>


-   単体ファイルの登録

     $ touch hello
     $ git add hello


-   複数ファイルの登録
                         ステージ状態

     $   mkdir foo
     $   touch foo/bar
     $   touch foo/baz
     $   git add foo



-   全てのファイルを登録

     $ git add .
ファイルをコミットする <git commit> 1/2


-   単体ファイルのコミット

     $ touch hello
     $ git add hello
     $ git commit -m "first commit"
     [master 697d7ac] first commit
      0 files changed, 0 insertions(+), 0 deletions(-)
      create mode 100644 hello


-   複数ファイルのコミット

     $ mkdir foo
     $ touch foo/bar
     $ touch foo/baz
     $ git add foo
     $ git commit -m "first commit"
     [master 1f615ff] first commit
      0 files changed, 0 insertions(+), 0 deletions(-)
      create mode 100644 foo/bar
      create mode 100644 foo/baz
ファイルをコミットする <git commit> 1/2


-   単体ファイルのコミット

                                        Gitではコメント入力が必須
     $ touch hello
     $ git add hello
     $ git commit -m "first commit"
     [master 697d7ac] first commit
      0 files changed, 0 insertions(+), 0 deletions(-)
      create mode 100644 hello
                     コミットハッシュの先頭文字

-   複数ファイルのコミット

     $ mkdir foo
     $ touch foo/bar
     $ touch foo/baz
     $ git add foo
     $ git commit -m "first commit"
     [master 1f615ff] first commit
      0 files changed, 0 insertions(+), 0 deletions(-)
      create mode 100644 foo/bar
      create mode 100644 foo/baz
ファイルをコミットする <git commit> 1/2


-   単体ファイルのコミット

                                        Gitではコメント入力が必須
     $ touch hello
     $ git add hello
     $ git commit -m "first commit"
     [master 697d7ac] first commit
      0 files changed, 0 insertions(+), 0 deletions(-)
      create mode 100644 hello
                     コミットハッシュの先頭文字

-   複数ファイルのコミット

     $ mkdir foo
     $ touch foo/bar
     $ touch foo/baz
     $ git add foo
     $ git commit -m "first commit"
     [master 1f615ff] first commit
      0 files changed, 0 insertions(+), 0 deletions(-)
      create mode 100644 foo/bar     git -m first commit -a fooで代用可能
      create mode 100644 foo/baz
ファイルをコミットする <git commit> 2/2


-   ファイル変更後の再コミット

     $ echo 'this is bar' > foo/bar
     $ echo 'this is baz' > foo/baz
     $ git add foo/bar
     $ git commit
     # On branch master
     # Your branch is ahead of 'origin/master' by 7 commits.
     #
     # Changes not staged for commit:
     #   (use "git add <file>..." to update what will be committed)
     #   (use "git checkout -- <file>..." to discard changes in
     working directory)
     #
     #   modified:   foo/bar
     #
ファイルをコミットする <git commit> 2/2


-   ファイル変更後の再コミット

     $ echo 'this is bar' > foo/bar
     $ echo 'this is baz' > foo/baz
     $ git add foo/bar
     $ git commit
     # On branch master
     # Your branch is barのみインデックスに登録
                       ahead of 'origin/master' by 7 commits.
     #
     # Changes not staged for commit:
     #   (use "git add <file>..." to update what will be committed)
     #   (use "git checkout -- <file>..." to discard changes in
     working directory)
     #
     #   modified:   foo/bar
     #

                               bazはコミット対象外
コミットの詳細を確認する <git show>


-   特定のコミットで変更されたファイル一覧を取得


     $ touch file_1 file_2 file_3
     $ git add .
     $ git commit -m "first commit"

     $ git log
     commit dd3ba389a19e85265bd5d382733a86900a56ffe8
     ...

     $ git show --name-only dd3ba389a19e85265bd5d382733a86900a56ffe8
     commit dd3ba389a19e85265bd5d382733a86900a56ffe8
     Author: {your_name} <{your_email}>
     Date:   Sun Apr 22 01:41:03 2012 +0900

         first commit

     file_1
     file_2
     file_3
コミットの詳細を確認する <git show>


-   特定のコミットで変更されたファイル一覧を取得


     $ touch file_1 file_2 file_3
     $ git add .                                       コミットハッシュ値
     $ git commit -m "first commit"

     $ git log
     commit dd3ba389a19e85265bd5d382733a86900a56ffe8
     ...

     $ git show --name-only dd3ba389a19e85265bd5d382733a86900a56ffe8
     commit dd3ba389a19e85265bd5d382733a86900a56ffe8
     Author: {your_name} <{your_email}>
     Date:   Sun Apr 22 01:41:03 2012 +0900          dd3ba...のコミット内容を確認

         first commit

     file_1
     file_2
     file_3


              dd3ba...でコミットされたファイルの一覧
リモートリポジトリへの反映 <git push>


-   インデックスに登録されているファイルをプッシュする

     $ touch hello
     $ git add .
     $ git commit -m "first commit"
     [master 4ccbdef] first commit
      0 files changed, 0 insertions(+), 0 deletions(-)
      create mode 100644 hello
     $ git push
     Counting objects: 28, done.
     Delta compression using up to 4 threads.
     Compressing objects: 100% (20/20), done.
     Writing objects: 100% (27/27), 2.14 KiB, done.
     Total 27 (delta 3), reused 2 (delta 0)
     To git@{fqdn}:test
        a22beb4..4ccbdef master -> master
リモートリポジトリへの反映 <git push>


-   インデックスに登録されているファイルをプッシュする

     $ touch hello
     $ git add .
     $ git commit -m "first commit"
     [master 4ccbdef] first commit
      0 files changed, 0 insertions(+), 0 deletions(-)
      create mode 100644 hello
     $ git push
     Counting objects: 28, done.
     Delta compression using up to 4 threads.
     Compressing objects: 100% (20/20), done.
     Writing objects: 100% (27/27), 2.14 KiB, done.
     Total 27 (delta 3), reused 2 (delta 0)
     To git@{fqdn}:test
        a22beb4..4ccbdef master -> master



                                                         push成功通知
リモートリポジトリから差分を取得 <git pull>


-   他のリポジトリの変更点をローカルリポジトリにマージする

     $ git pull
     remote: Counting objects: 5, done.
     remote: Total 3 (delta 0), reused 0 (delta 0)
     Unpacking objects: 100% (3/3), done.
     From {fqdn}:test
        4ccbdef..dafbd21 master      -> origin/master
     Updating 4ccbdef..dafbd21
     Fast-forward
      hello |     1 +
      1 files changed, 1 insertions(+), 0 deletions(-)
リモートリポジトリから差分を取得 <git pull>


-   他のリポジトリの変更点をローカルリポジトリにマージする

     $ git pull
     remote: Counting objects: 5, done.
     remote: Total 3 (delta 0), reused 0 (delta 0)
     Unpacking objects: 100% (3/3), done.
     From {fqdn}:test
        4ccbdef..dafbd21 master      -> origin/master
     Updating 4ccbdef..dafbd21
     Fast-forward
      hello |     1 +
      1 files changed, 1 insertions(+), 0 deletions(-)



                                                         pull成功通知
変更が加えられたファイルを表示 <git status>


-   ワーキングツリーやインデックス、リポジトリの状態を分類して表示する

     $ touch a b c d
     $ git add b c d
     $ git commit -m "c,d commited" c d
     $ echo 'REWRITE' > d
     $ git status
     # Changes to be committed:
     #   (use "git reset HEAD <file>..." to unstage)
     #
     #   new file:   b
     #
     # Changes not staged for commit:
     #   (use "git add <file>..." to update what will be committed)
     #   (use "git checkout -- <file>..." to discard changes in
     working directory)
     #
     #   modified:   d
     #
     # Untracked files:
     #   (use "git add <file>..." to include in what will be
     committed)
     #
     #   a
変更が加えられたファイルを表示 <git status>


-   ワーキングツリーやインデックス、リポジトリの状態を分類して表示する

     $ touch a b c d
     $ git add b c d
     $ git commit -m "c,d commited"ステージ状態(コミット待ち)
                                    c d
     $ echo 'REWRITE' > d
     $ git status
     # Changes to be committed:
     #   (use "git reset HEAD <file>..." to unstage)
     #
     #   new file:   b
     #
     # Changes not staged for commit:
     #   (use "git add <file>..." to update what will be committed)
     #   (use "git checkout -- <file>..." to discard changes in
     working directory)           修正状態(ステージ待ち)
     #
     #   modified:   d
     #
     # Untracked files:
     #   (use "git add <file>..." to include in what will be
     committed)
     #                  未追跡状態
     #   a
Gitにおけるファイルのライフサイクル


-   Untracked、Unmodified、Modified、Stagedの違いを理解する
コミットログの表示 <git log>


-   最新コミット(HEAD)からたどることができるログを表示する

     $ git log
     commit e738db944c0a03b130b2df628213449f6597c08e
     Author: {your_name} <{your_email}>
     Date:   Thu Apr 19 12:30:47 2012 +0900

           third commit

     commit 22a17381b6a514b0eaa511fa0c76edb7ba0bc46b
     Author: {your_name} <{your_email}>
     Date:   Thu Apr 19 12:16:27 2012 +0900

           second commit

     commit 22a17381b6a514b0eaa511fa0c76edb7ba0bc46b
     Author: {your_name} <{your_email}>
     Date:   Thu Apr 19 12:16:27 2012 +0900

           first commit
     ...
コミットログの表示 <git log>


-   最新コミット(HEAD)からたどることができるログを表示する
                                                       3回目のコミットログ

     $ git log
     commit e738db944c0a03b130b2df628213449f6597c08e
     Author: {your_name} <{your_email}>
     Date:   Thu Apr 19 12:30:47 2012 +0900
                                                       2回目のコミットログ
           third commit

     commit 22a17381b6a514b0eaa511fa0c76edb7ba0bc46b
     Author: {your_name} <{your_email}>
     Date:   Thu Apr 19 12:16:27 2012 +0900
                                                       1回目のコミットログ
           second commit

     commit 22a17381b6a514b0eaa511fa0c76edb7ba0bc46b
     Author: {your_name} <{your_email}>
     Date:   Thu Apr 19 12:16:27 2012 +0900

           first commit
     ...
ブランチ <git branch> 1/2


-   現在のブランチを確認する

     $ git branch
     * master


-   新しいブランチを作成する

     $ git branch new_branch
     $ git branch
     * master
       new_branch



-   新しいブランチをチェックアウトする

     $ git checkout new_branch
     Switched to branch 'new_branch'
     $ git branch
       master
     * new_branch
ブランチ <git branch> 1/2


-   現在のブランチを確認する
                    *(アスタリスク)はカレントブランチを示す

     $ git branch
     * master


-   新しいブランチを作成する

     $ git branch new_branch
     $ git branch
     * master
       new_branch



-   新しいブランチをチェックアウトする

     $ git checkout new_branch
     Switched to branch 'new_branch'
     $ git branch
       master
     * new_branch
ブランチ <git branch> 1/2


-   現在のブランチを確認する
                    *(アスタリスク)はカレントブランチを示す

     $ git branch
     * master


-   新しいブランチを作成する
                  ブランチ作成後もカレントブランチはmasterのまま
     $ git branch new_branch
     $ git branch
     * master
       new_branch



-   新しいブランチをチェックアウトする

     $ git checkout new_branch
     Switched to branch 'new_branch'
     $ git branch
       master
     * new_branch
ブランチ <git branch> 1/2


-   現在のブランチを確認する
                    *(アスタリスク)はカレントブランチを示す

     $ git branch
     * master


-   新しいブランチを作成する
                  ブランチ作成後もカレントブランチはmasterのまま
     $ git branch new_branch
     $ git branch
     * master
       new_branch



-   新しいブランチをチェックアウトする

     $ git checkout new_branch
     Switched to branch 'new_branch'
                     カレントブランチが切り替わる
     $ git branch
       master
     * new_branch
ブランチ <git branch> 2/2


-   新しいブランチをプッシュする

     $ git push origin new_branch
     Counting objects: 19, done.
     Delta compression using up to 4 threads.
     Compressing objects: 100% (14/14), done.
     Writing objects: 100% (17/17), 1.45 KiB, done.
     Total 17 (delta 5), reused 1 (delta 0)
     To git@{fqdn}:test
      * [new branch]      new_branch -> new_branch



-   リモートを含めた全てのブランチを確認する

     $ git branch -a
       master
     * new_branch
       remotes/origin/HEAD -> origin/master
       remotes/origin/master
       remotes/origin/new_branch
ブランチ <git branch> 2/2


-   新しいブランチをプッシュする
                                                      リモートブランチの作成成功通知

     $ git push origin new_branch
     Counting objects: 19, done.
     Delta compression using up to 4 threads.
     Compressing objects: 100% (14/14), done.
     Writing objects: 100% (17/17), 1.45 KiB, done.
     Total 17 (delta 5), reused 1 (delta 0)
     To git@{fqdn}:test
      * [new branch]      new_branch -> new_branch



-   リモートを含めた全てのブランチを確認する

     $ git branch -a
       master
     * new_branch
       remotes/origin/HEAD -> origin/master
       remotes/origin/master
       remotes/origin/new_branch
ブランチ <git branch> 2/2


-   新しいブランチをプッシュする
                                                      リモートブランチの作成成功通知

     $ git push origin new_branch
     Counting objects: 19, done.
     Delta compression using up to 4 threads.
     Compressing objects: 100% (14/14), done.
     Writing objects: 100% (17/17), 1.45 KiB, done.
     Total 17 (delta 5), reused 1 (delta 0)
     To git@{fqdn}:test
      * [new branch]      new_branch -> new_branch



-   リモートを含めた全てのブランチを確認する

     $ git branch -a
       master
     * new_branch
       remotes/origin/HEAD -> origin/master
       remotes/origin/master
       remotes/origin/new_branch

                                    リモートにnew_branchが作成されていることがわかる
差分の比較 1/3


-       git diff

    -         ワーキングツリーとインデックスの差分を比較

          -    ステージングされていないファイルは比較できない

    -         インデックスにファイルが登録された状態で、更に同じファイルを更新
              した場合に使う

    -         インデックス登録とコミットを同時に行う場合はあまり使わない
差分の比較 2/3


-       git diff --cached

    -     HEADとインデックスの差分を表示する

    -     インデックスに登録されたファイルをコミットする前に使用する
差分の比較 3/3


-       git diff HEAD

    -     HEADとワーキングツリーの比較

    -     前回コミットからどれくらい編集されているか調べる際に使用する

    -      HEAD の部分はHEAD^やコミットのハッシュ値を指定することも可能
一部のディレクトリのみチェックアウト


-       GitはSubversionのように一部のディレクトリのみチェックアウトすること
        ができない

-       Git 1.7から導入されたSprase checkout機能を使う

    -     Sparse checkout example in git 1.7.0

         $ git clone git@{fqdn}:common
         Cloning into common...
         remote: Counting objects: 2134, done.
         remote: Compressing objects: 100% (1173/1173), done.
         commremote: Total 2134 (delta 906), reused 2125 (delta 903)
         Receiving objects: 100% (2134/2134), 24.22 MiB |次回以降はgit pullでproject
                                                          579 KiB/s, done.
         Resolving deltas: 100% (906/906), done.)        のみがチェックアウトされる
         $ cd common/
         $ git config core.sparsecheckout true
         $ echo project/ > .git/info/sparse-checkout
         $ git read-tree -m -u HEAD
特定のファイル・ディレクトリをコミット対象外にする


-   特定のファイルをコミット対象外にする

     $ touch a b
     $ echo 'b' > .gitignore
     $ git add .
     $ git commit -m "ignore commit"
     [master 2bfa6b1] ignore commit
      1 files changed, 1 insertions(+), 0 deletions(-)
      create mode 100644 .gitignore




-   特定のディレクトリの内容をコミット対象外とする

     $ mkdir logs
     $ touch logs/a logs/b logs/c
     $ echo 'logs/' > .gitignore
     $ echo '!.gitignore' >> .gitignore
     $ touch logs/.gitignore
     $ git add .
     $ git commit -m "ignore commit"
     [master 9a9a128] ignore commit
      0 files changed, 0 insertions(+), 0 deletions(-)
      delete mode 100644 a
特定のファイル・ディレクトリをコミット対象外にする


-   特定のファイルをコミット対象外にする

     $ touch a b
     $ echo 'b' > .gitignore
                                                         ファイルbはコミットされない
     $ git add .
     $ git commit -m "ignore commit"
     [master 2bfa6b1] ignore commit
      1 files changed, 1 insertions(+), 0 deletions(-)
      create mode 100644 .gitignore




-   特定のディレクトリの内容をコミット対象外とする

     $ mkdir logs
     $ touch logs/a logs/b logs/c
     $ echo 'logs/' > .gitignore
     $ echo '!.gitignore' >> .gitignore
     $ touch logs/.gitignore
     $ git add .
     $ git commit -m "ignore commit"
     [master 9a9a128] ignore commit
      0 files changed, 0 insertions(+), 0 deletions(-)
      delete mode 100644 a
特定のファイル・ディレクトリをコミット対象外にする


-   特定のファイルをコミット対象外にする

     $ touch a b
     $ echo 'b' > .gitignore
                                                         ファイルbはコミットされない
     $ git add .
     $ git commit -m "ignore commit"
     [master 2bfa6b1] ignore commit
      1 files changed, 1 insertions(+), 0 deletions(-)
      create mode 100644 .gitignore




-   特定のディレクトリの内容をコミット対象外とする
                                                        「!」は否定
     $ mkdir logs                          logs下は対象外とするが、.gitignoreはコミット対象とする
     $ touch logs/a logs/b logs/c
     $ echo 'logs/' > .gitignore
     $ echo '!.gitignore' >> .gitignore
     $ touch logs/.gitignore
     $ git add .
     $ git commit -m "ignore commit"         Gitは空ディレクトリを削除してしまうので、
     [master 9a9a128] ignore commit
                                                    ダミーファイルを作成しておく
      0 files changed, 0 insertions(+), 0 deletions(-)
      delete mode 100644 a
コミットメールの見方


-   プロジェクトの開発関係者にメールが通知される

     This is an automated email from the git hooks/post-receive script. It was
     generated because a ref change was pushed to the repository containing
     the project "mars".

     The branch, 1.10 has been updated
            via f46534818a5432b212e2a24c9d00f706ba7df5f4 (commit)
           from 3759217a665beabb6f17a81c8e3b26b5c9c02920 (commit)

     Those revisions listed above that are new to this repository have
     not appeared on any other notification email; so we list those
     revisions in full, below.

     - Log -----------------------------------------------------------------
     commit f46534818a5432b212e2a24c9d00f706ba7df5f4
     Author: {your_name} <{your_email}>
     Date:   Thu Apr 19 13:39:12 2012 +0900

         first commit
     -----------------------------------------------------------------------

     Summary of changes:
      VERSION |    2 +-
      1 files changed, 1 insertions(+), 1 deletions(-)

     hooks/post-receive
     --
     mars
コミットメールの見方


-   プロジェクトの開発関係者にメールが通知される

     This is an automated email from the git hooks/post-receive script. It was
     generated because a ref change was pushed to the repository containing
     the project "mars".

     The branch, 1.10 has been updated
            via f46534818a5432b212e2a24c9d00f706ba7df5f4 (commit)
           from 3759217a665beabb6f17a81c8e3b26b5c9c02920 (commit)

     Those revisions listed above that are new to this repository have
     not appeared on any other notification email; so we list ブランチ情報、コミットハッシュ情報
                                                              those
     revisions in full, below.

     - Log -----------------------------------------------------------------
     commit f46534818a5432b212e2a24c9d00f706ba7df5f4
     Author: {your_name} <{your_email}>
     Date:   Thu Apr 19 13:39:12 2012 +0900

         first commit
     -----------------------------------------------------------------------

     Summary of changes:
      VERSION |    2 +-
      1 files changed, 1 insertions(+), 1 deletions(-)

     hooks/post-receive
     --
     mars
コミットメールの見方


-   プロジェクトの開発関係者にメールが通知される

     This is an automated email from the git hooks/post-receive script. It was
     generated because a ref change was pushed to the repository containing
     the project "mars".

     The branch, 1.10 has been updated
            via f46534818a5432b212e2a24c9d00f706ba7df5f4 (commit)
           from 3759217a665beabb6f17a81c8e3b26b5c9c02920 (commit)

     Those revisions listed above that are new to this repository have
     not appeared on any other notification email; so we list ブランチ情報、コミットハッシュ情報
                                                              those
     revisions in full, below.

     - Log -----------------------------------------------------------------
     commit f46534818a5432b212e2a24c9d00f706ba7df5f4
     Author: {your_name} <{your_email}>
     Date:   Thu Apr 19 13:39:12 2012 +0900               コミットログ情報

         first commit
     -----------------------------------------------------------------------

     Summary of changes:
      VERSION |    2 +-
      1 files changed, 1 insertions(+), 1 deletions(-)

     hooks/post-receive
     --
     mars
コミットメールの見方


-   プロジェクトの開発関係者にメールが通知される

     This is an automated email from the git hooks/post-receive script. It was
     generated because a ref change was pushed to the repository containing
     the project "mars".

     The branch, 1.10 has been updated
            via f46534818a5432b212e2a24c9d00f706ba7df5f4 (commit)
           from 3759217a665beabb6f17a81c8e3b26b5c9c02920 (commit)

     Those revisions listed above that are new to this repository have
     not appeared on any other notification email; so we list ブランチ情報、コミットハッシュ情報
                                                              those
     revisions in full, below.

     - Log -----------------------------------------------------------------
     commit f46534818a5432b212e2a24c9d00f706ba7df5f4
     Author: {your_name} <{your_email}>
     Date:   Thu Apr 19 13:39:12 2012 +0900               コミットログ情報

         first commit
     -----------------------------------------------------------------------

     Summary of changes:
      VERSION |    2 +-
                                                           変更されたファイルの情報
      1 files changed, 1 insertions(+), 1 deletions(-)

     hooks/post-receive
     --
     mars
トラブルシューティング
ファイルが一方にしか存在しない 1/3


-   テストケース

    1. リポジトリAでa∼cのファイルを作成後にプッシュ

    2. リポジトリBでプルする

    3. リポジトリAでdのファイルを作成後にプッシュ

    4. リポジトリBでプッシュする

    5. この後何が起こるか?
ファイルが一方にしか存在しない 2/3


-   リポジトリBでプッシュした直後のレスポンス

     $ git push
     To git@{fqdn}:test
      ! [rejected]        master -> master (non-fast-forward)
     error: failed to push some refs to 'git@{fqdn}:test'
     To prevent you from losing history, non-fast-forward updates
     were rejected
     Merge the remote changes (e.g. 'git pull') before pushing
     again. See the
     'Note about fast-forwards' section of 'git push --help' for
     details.
ファイルが一方にしか存在しない 2/3


-   リポジトリBでプッシュした直後のレスポンス

     $ git push
     To git@{fqdn}:test
      ! [rejected]        master -> master (non-fast-forward)
     error: failed to push some refs to 'git@{fqdn}:test'
     To prevent you from losing history, non-fast-forward updates
     were rejected
     Merge the remote changes (e.g. 'git pull') before pushing
     again. See the
     'Note about fast-forwards' section of 'git push --help' for
     details.


                               non-fast-forwardとなり、プッシュに失敗する
ファイルが一方にしか存在しない 3/3


-   対策:リモートリポジトリの差分を取得後にプッシュする

     $ git pull
     remote: Counting objects: 3, done.
     remote: Compressing objects: 100% (2/2), done.
     remote: Total 2 (delta 1), reused 0 (delta 0)
     Unpacking objects: 100% (2/2), done.
     From {fqdn}:test
        05e23a1..ae8a6a6 master      -> origin/master
     Merge made by recursive.
      0 files changed, 0 insertions(+), 0 deletions(-)
      create mode 100644 d
     $ git push
     Counting objects: 14, done.
     Delta compression using up to 4 threads.
     Compressing objects: 100% (7/7), done.
     Writing objects: 100% (9/9), 958 bytes, done.
     Total 9 (delta 2), reused 1 (delta 0)
     To git@{fqdn}:test
        ae8a6a6..53fe5ce master -> master
ファイルが一方にしか存在しない 3/3


-   対策:リモートリポジトリの差分を取得後にプッシュする

     $ git pull
     remote: Counting objects: 3, done.
     remote: Compressing objects: 100% (2/2), done.
     remote: Total 2 (delta 1), reused 0 (delta 0)
     Unpacking objects: 100% (2/2), done.
     From {fqdn}:test
        05e23a1..ae8a6a6 master      -> origin/master
     Merge made by recursive.
      0 files changed, 0 insertions(+), 0 deletions(-)
      create mode 100644 d
     $ git push                                       push成功通知
     Counting objects: 14, done.
     Delta compression using up to 4 threads.
     Compressing objects: 100% (7/7), done.
     Writing objects: 100% (9/9), 958 bytes, done.
     Total 9 (delta 2), reused 1 (delta 0)
     To git@{fqdn}:test
        ae8a6a6..53fe5ce master -> master
ファイルの競合 1/3


-   テストケース

    1. リポジトリAでhelloファイルを「WRITE FROM REP-A」として保存

    2. helloをコミットしてリモートにプッシュする

    3. リポジトリBでhelloファイルを「WRITE FROM REP-B」として保存

    4. helloをコミットしてリモートにプッシュする

    5. この後何が起こるか?
ファイルの競合 2/3


-   リポジトリBでhelloをプッシュした直後のレスポンス

     $ git push
     To git@{fqdn}:test
      ! [rejected]        master -> master (non-fast-forward)
     error: failed to push some refs to 'git@{fqdn}:test'
     To prevent you from losing history, non-fast-forward updates
     were rejected
     Merge the remote changes (e.g. 'git pull') before pushing
     again. See the
     'Note about fast-forwards' section of 'git push --help' for
     details.
ファイルの競合 2/3


-   リポジトリBでhelloをプッシュした直後のレスポンス

     $ git push
     To git@{fqdn}:test
      ! [rejected]        master -> master (non-fast-forward)
     error: failed to push some refs to 'git@{fqdn}:test'
     To prevent you from losing history, non-fast-forward updates
     were rejected
     Merge the remote changes (e.g. 'git pull') before pushing
     again. See the
     'Note about fast-forwards' section of 'git push --help' for
     details.


                               non-fast-forwardとなり、プッシュに失敗する
ファイルの競合 3/3


-       対策:他のリポジトリの変更を取得し、差分をチェックする

          $ git fetch
          $ git diff FETCH_HEAD
          diff --git a/hello b/hello
          index 10cf535..843c591 100644
          --- a/hello
          +++ b/hello
          @@ -1 +1 @@
          -w-200
          +REWRITE B



-       git fetch

    -      他のリポジトリの変更をFETCH_HEADに格納する

-       git diff FETCH_HEAD

    -      ローカルとリモートリポジトリの差分を取得
ファイルの競合 3/3


-       対策:他のリポジトリの変更を取得し、差分をチェックする

          $ git fetch
          $ git diff FETCH_HEAD
          diff --git a/hello b/hello
          index 10cf535..843c591 100644
          --- a/hello
          +++ b/hello
          @@ -1 +1 @@
          -w-200
          +REWRITE B



-       git fetch                         ファイルの差分が表示される


    -      他のリポジトリの変更をFETCH_HEADに格納する

-       git diff FETCH_HEAD

    -      ローカルとリモートリポジトリの差分を取得
コンフリクトファイルの修正 1/3


-   テストケース

    1. リポジトリAでhelloファイルを「WRITE FROM REP-A」として保存

    2. helloをコミットしてリモートにプッシュする

    3. リポジトリBでhelloファイルを「WRITE FROM REP-B」として保存

    4. helloをコミット

    5. リポジトリBでリモートの反映をプルする

    6. この後何が起こるか?
コンフリクトファイルの修正 2/3


-   リポジトリBでプルした直後のレスポンス

     $ git pull
     ls remote: Counting objects: 5, done.
     remote: Compressing objects: 100% (2/2), done.
     remote: Total 3 (delta 1), reused 0 (delta 0)
     Unpacking objects: 100% (3/3), done.
     From {fqdn}:test
        186584c..22a1738 master      -> origin/master
     Auto-merging hello
     CONFLICT (content): Merge conflict in hello
     Automatic merge failed; fix conflicts and then commit the
     result.
コンフリクトファイルの修正 2/3


-   リポジトリBでプルした直後のレスポンス

     $ git pull
     ls remote: Counting objects: 5, done.
     remote: Compressing objects: 100% (2/2), done.
     remote: Total 3 (delta 1), reused 0 (delta 0)
     Unpacking objects: 100% (3/3), done.
     From {fqdn}:test
        186584c..22a1738 master      -> origin/master
     Auto-merging hello
     CONFLICT (content): Merge conflict in hello
     Automatic merge failed; fix conflicts and then commit the
     result.


                                                 マージ中にコンフリクトが発生
コンフリクトファイルの修正 3/3


-   対策:変更が加えられたファイルの一覧を表示する

     $ git status
     # On branch master
     # Your branch and 'origin/master' have diverged,
     # and have 1 and 1 different commit(s) each, respectively.
     #
     # Unmerged paths:
     #   (use "git add/rm <file>..." as appropriate to mark
     resolution)
     #
     #   both modified:      hello
     #




     $ cat hello
     <<<<<<< HEAD
     WRITE FROM REP-B
     =======
     WRITE FROM REP-A
     >>>>>>> 22a17381b6a514b0eaa511fa0c76edb7ba0bc46b
コンフリクトファイルの修正 3/3


-   対策:変更が加えられたファイルの一覧を表示する

     $ git status
     # On branch master
                                                   マージに失敗したファイルの一覧
     # Your branch and 'origin/master' have diverged,
     # and have 1 and 1 different commit(s) each, respectively.
     #
     # Unmerged paths:
     #   (use "git add/rm <file>..." as appropriate to mark
     resolution)
     #
     #   both modified:      hello
     #




     $ cat hello
     <<<<<<< HEAD
     WRITE FROM REP-B
     =======
     WRITE FROM REP-A
     >>>>>>> 22a17381b6a514b0eaa511fa0c76edb7ba0bc46b
終わりに
Gitの運用フロー


-       Gitは自由度が高いため、運用フローを決めないと使いにくい

-       運用モデルの1つに「A successful Git branching model」がある

    -     http://nvie.com/posts/a-successful-git-branching-model/

    -     安定ブランチ(master)、開発ブランチ(develop)を主軸とし、ホッ
          トフィックスやリリースの度にサポートブランチを作成・破棄していく

    -     このモデルをサポートするgit-flowというプラグインがある
参考資料


-       Pro Git(En/Ja)

    -     http://progit.org/ebook/progit.pdf

-       Gitによるバージョン管理

Más contenido relacionado

La actualidad más candente

CI/CDツール比較してみた
CI/CDツール比較してみたCI/CDツール比較してみた
CI/CDツール比較してみたShoya Kai
 
一人でもはじめるGitでバージョン管理
一人でもはじめるGitでバージョン管理一人でもはじめるGitでバージョン管理
一人でもはじめるGitでバージョン管理Takafumi Yoshida
 
Gitはじめの一歩
Gitはじめの一歩Gitはじめの一歩
Gitはじめの一歩Ayana Yokota
 
Git SourceTreeでバージョン管理しよう
Git SourceTreeでバージョン管理しようGit SourceTreeでバージョン管理しよう
Git SourceTreeでバージョン管理しよう富士見研究所
 
Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An IntroductionBehzad Altaf
 
Gitの便利ワザ
Gitの便利ワザGitの便利ワザ
Gitの便利ワザktateish
 
こわくない Git
こわくない Gitこわくない Git
こわくない GitKota Saito
 
Gitのよく使うコマンド
Gitのよく使うコマンドGitのよく使うコマンド
Gitのよく使うコマンドYUKI Kaoru
 
はじめようGit
はじめようGitはじめようGit
はじめようGittechscore
 
やさしいGitの内部構造 - yapcasia2013
やさしいGitの内部構造 - yapcasia2013やさしいGitの内部構造 - yapcasia2013
やさしいGitの内部構造 - yapcasia2013DQNEO
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHubJames Gray
 
バージョン管理システム比較資料
バージョン管理システム比較資料バージョン管理システム比較資料
バージョン管理システム比較資料suzzsegv
 
世界一わかりやすいClean Architecture
世界一わかりやすいClean Architecture世界一わかりやすいClean Architecture
世界一わかりやすいClean ArchitectureAtsushi Nakamura
 
デザイナのためのGit入門
デザイナのためのGit入門デザイナのためのGit入門
デザイナのためのGit入門dsuke Takaoka
 

La actualidad más candente (20)

Git由超淺入超深
Git由超淺入超深Git由超淺入超深
Git由超淺入超深
 
Git
GitGit
Git
 
CI/CDツール比較してみた
CI/CDツール比較してみたCI/CDツール比較してみた
CI/CDツール比較してみた
 
一人でもはじめるGitでバージョン管理
一人でもはじめるGitでバージョン管理一人でもはじめるGitでバージョン管理
一人でもはじめるGitでバージョン管理
 
Git 勉強会
Git 勉強会Git 勉強会
Git 勉強会
 
Gitはじめの一歩
Gitはじめの一歩Gitはじめの一歩
Gitはじめの一歩
 
Git SourceTreeでバージョン管理しよう
Git SourceTreeでバージョン管理しようGit SourceTreeでバージョン管理しよう
Git SourceTreeでバージョン管理しよう
 
C++ マルチスレッド 入門
C++ マルチスレッド 入門C++ マルチスレッド 入門
C++ マルチスレッド 入門
 
Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An Introduction
 
Git & GitHub WorkShop
Git & GitHub WorkShopGit & GitHub WorkShop
Git & GitHub WorkShop
 
Gitの便利ワザ
Gitの便利ワザGitの便利ワザ
Gitの便利ワザ
 
こわくない Git
こわくない Gitこわくない Git
こわくない Git
 
Gitのよく使うコマンド
Gitのよく使うコマンドGitのよく使うコマンド
Gitのよく使うコマンド
 
はじめようGit
はじめようGitはじめようGit
はじめようGit
 
やさしいGitの内部構造 - yapcasia2013
やさしいGitの内部構造 - yapcasia2013やさしいGitの内部構造 - yapcasia2013
やさしいGitの内部構造 - yapcasia2013
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 
バージョン管理システム比較資料
バージョン管理システム比較資料バージョン管理システム比較資料
バージョン管理システム比較資料
 
世界一わかりやすいClean Architecture
世界一わかりやすいClean Architecture世界一わかりやすいClean Architecture
世界一わかりやすいClean Architecture
 
デザイナのためのGit入門
デザイナのためのGit入門デザイナのためのGit入門
デザイナのためのGit入門
 

Destacado

ポイントをおさえて移行しよう!Git乗り換え超初級
ポイントをおさえて移行しよう!Git乗り換え超初級ポイントをおさえて移行しよう!Git乗り換え超初級
ポイントをおさえて移行しよう!Git乗り換え超初級Kouji Matsui
 
もしWordPressユーザーがGitを使ったら 〜WordPressテーマを共同編集しよう〜
もしWordPressユーザーがGitを使ったら 〜WordPressテーマを共同編集しよう〜もしWordPressユーザーがGitを使ったら 〜WordPressテーマを共同編集しよう〜
もしWordPressユーザーがGitを使ったら 〜WordPressテーマを共同編集しよう〜Takashi Uemura
 
はじめてのGit forデザイナー&コーダー
はじめてのGit forデザイナー&コーダーはじめてのGit forデザイナー&コーダー
はじめてのGit forデザイナー&コーダーSaeko Yamamoto
 
Git勉強会 2016 Gitで卒論を管理しよう回
Git勉強会 2016 Gitで卒論を管理しよう回Git勉強会 2016 Gitで卒論を管理しよう回
Git勉強会 2016 Gitで卒論を管理しよう回kinme modoki
 
ブランチを綺麗に保ち、どうやって本番アップするのか
ブランチを綺麗に保ち、どうやって本番アップするのかブランチを綺麗に保ち、どうやって本番アップするのか
ブランチを綺麗に保ち、どうやって本番アップするのかSaeko Yamamoto
 
RSpecの実行速度を3.5倍にした話
RSpecの実行速度を3.5倍にした話RSpecの実行速度を3.5倍にした話
RSpecの実行速度を3.5倍にした話Naomichi Yamakita
 
GIT Workflows
GIT Workflows GIT Workflows
GIT Workflows BraveBits
 
はじめてのGit #gitkyoto
はじめてのGit #gitkyotoはじめてのGit #gitkyoto
はじめてのGit #gitkyotoHisateru Tanaka
 
Railsチュートリアル(second)を終えて
Railsチュートリアル(second)を終えてRailsチュートリアル(second)を終えて
Railsチュートリアル(second)を終えてHirata Tomoko
 
Team Founfation Server / Visual Studio Online ハンズオン トレーニング手順書
Team Founfation Server / Visual Studio Online  ハンズオン トレーニング手順書Team Founfation Server / Visual Studio Online  ハンズオン トレーニング手順書
Team Founfation Server / Visual Studio Online ハンズオン トレーニング手順書Masaki Takeda
 
git gitにされたオレの屍を超えていけ
git gitにされたオレの屍を超えていけgit gitにされたオレの屍を超えていけ
git gitにされたオレの屍を超えていけDaisuke Kasuya
 
サラリーマンでギョーミーなプログラマ(つまりオレ)でも片手間で作れるXFD
サラリーマンでギョーミーなプログラマ(つまりオレ)でも片手間で作れるXFDサラリーマンでギョーミーなプログラマ(つまりオレ)でも片手間で作れるXFD
サラリーマンでギョーミーなプログラマ(つまりオレ)でも片手間で作れるXFDKazuhito Miura
 
SCMBC Git入門セッション発表資料
SCMBC Git入門セッション発表資料SCMBC Git入門セッション発表資料
SCMBC Git入門セッション発表資料bleis tift
 
Team Foundation Server プロセステンプレートの変更 手順書
Team Foundation Server プロセステンプレートの変更 手順書Team Foundation Server プロセステンプレートの変更 手順書
Team Foundation Server プロセステンプレートの変更 手順書Masaki Takeda
 

Destacado (18)

ポイントをおさえて移行しよう!Git乗り換え超初級
ポイントをおさえて移行しよう!Git乗り換え超初級ポイントをおさえて移行しよう!Git乗り換え超初級
ポイントをおさえて移行しよう!Git乗り換え超初級
 
もしWordPressユーザーがGitを使ったら 〜WordPressテーマを共同編集しよう〜
もしWordPressユーザーがGitを使ったら 〜WordPressテーマを共同編集しよう〜もしWordPressユーザーがGitを使ったら 〜WordPressテーマを共同編集しよう〜
もしWordPressユーザーがGitを使ったら 〜WordPressテーマを共同編集しよう〜
 
はじめてのGit forデザイナー&コーダー
はじめてのGit forデザイナー&コーダーはじめてのGit forデザイナー&コーダー
はじめてのGit forデザイナー&コーダー
 
Git勉強会 2016 Gitで卒論を管理しよう回
Git勉強会 2016 Gitで卒論を管理しよう回Git勉強会 2016 Gitで卒論を管理しよう回
Git勉強会 2016 Gitで卒論を管理しよう回
 
ブランチを綺麗に保ち、どうやって本番アップするのか
ブランチを綺麗に保ち、どうやって本番アップするのかブランチを綺麗に保ち、どうやって本番アップするのか
ブランチを綺麗に保ち、どうやって本番アップするのか
 
Git (運用編)
Git (運用編)Git (運用編)
Git (運用編)
 
RSpecの実行速度を3.5倍にした話
RSpecの実行速度を3.5倍にした話RSpecの実行速度を3.5倍にした話
RSpecの実行速度を3.5倍にした話
 
いまさらJavaScript
いまさらJavaScriptいまさらJavaScript
いまさらJavaScript
 
GIT Workflows
GIT Workflows GIT Workflows
GIT Workflows
 
Terraforming
TerraformingTerraforming
Terraforming
 
はじめてのGit #gitkyoto
はじめてのGit #gitkyotoはじめてのGit #gitkyoto
はじめてのGit #gitkyoto
 
Railsチュートリアル(second)を終えて
Railsチュートリアル(second)を終えてRailsチュートリアル(second)を終えて
Railsチュートリアル(second)を終えて
 
Team Founfation Server / Visual Studio Online ハンズオン トレーニング手順書
Team Founfation Server / Visual Studio Online  ハンズオン トレーニング手順書Team Founfation Server / Visual Studio Online  ハンズオン トレーニング手順書
Team Founfation Server / Visual Studio Online ハンズオン トレーニング手順書
 
git gitにされたオレの屍を超えていけ
git gitにされたオレの屍を超えていけgit gitにされたオレの屍を超えていけ
git gitにされたオレの屍を超えていけ
 
サラリーマンでギョーミーなプログラマ(つまりオレ)でも片手間で作れるXFD
サラリーマンでギョーミーなプログラマ(つまりオレ)でも片手間で作れるXFDサラリーマンでギョーミーなプログラマ(つまりオレ)でも片手間で作れるXFD
サラリーマンでギョーミーなプログラマ(つまりオレ)でも片手間で作れるXFD
 
SCMBC Git入門セッション発表資料
SCMBC Git入門セッション発表資料SCMBC Git入門セッション発表資料
SCMBC Git入門セッション発表資料
 
Wagby on Cloud Foundry
Wagby on Cloud FoundryWagby on Cloud Foundry
Wagby on Cloud Foundry
 
Team Foundation Server プロセステンプレートの変更 手順書
Team Foundation Server プロセステンプレートの変更 手順書Team Foundation Server プロセステンプレートの変更 手順書
Team Foundation Server プロセステンプレートの変更 手順書
 

Similar a Git (実践入門編)

Git-dojo In Sendagaya.rb
Git-dojo In Sendagaya.rbGit-dojo In Sendagaya.rb
Git-dojo In Sendagaya.rbJun Fukaya
 
今さら聞けない人のためのGit超入門 GitLab 14対応版
今さら聞けない人のためのGit超入門 GitLab 14対応版今さら聞けない人のためのGit超入門 GitLab 14対応版
今さら聞けない人のためのGit超入門 GitLab 14対応版VirtualTech Japan Inc./Begi.net Inc.
 
Version Control System Tutorial バージョン管理システムチュートリアル
Version Control System Tutorial バージョン管理システムチュートリアルVersion Control System Tutorial バージョン管理システムチュートリアル
Version Control System Tutorial バージョン管理システムチュートリアルComputational Materials Science Initiative
 
猫にはわからないGit講座
猫にはわからないGit講座猫にはわからないGit講座
猫にはわからないGit講座Yusei Yamanaka
 
ソフトウェア工学2023 08 GitHub
ソフトウェア工学2023 08 GitHubソフトウェア工学2023 08 GitHub
ソフトウェア工学2023 08 GitHubToru Tamaki
 
Git -分散バージョン管理システム-
Git -分散バージョン管理システム-Git -分散バージョン管理システム-
Git -分散バージョン管理システム-Koji Shinba
 
git 初めの一歩
git 初めの一歩git 初めの一歩
git 初めの一歩Shin Yoshida
 
GitLab + Dokku で作る CI/CD 環境
GitLab + Dokku で作る CI/CD 環境GitLab + Dokku で作る CI/CD 環境
GitLab + Dokku で作る CI/CD 環境Kazuhiro Nishiyama
 
いいこんぶGitマニュアル
いいこんぶGitマニュアルいいこんぶGitマニュアル
いいこんぶGitマニュアルKaito Yuuki
 
バージョン管理システムチュートリアル
バージョン管理システムチュートリアルバージョン管理システムチュートリアル
バージョン管理システムチュートリアルRyo Igarashi
 
Git lev 1-おひとりさま用-
Git lev 1-おひとりさま用-Git lev 1-おひとりさま用-
Git lev 1-おひとりさま用-Kentarou Kurashige
 

Similar a Git (実践入門編) (20)

Git-dojo In Sendagaya.rb
Git-dojo In Sendagaya.rbGit-dojo In Sendagaya.rb
Git-dojo In Sendagaya.rb
 
今さら聞けない人のためのGit超入門 GitLab 14対応版
今さら聞けない人のためのGit超入門 GitLab 14対応版今さら聞けない人のためのGit超入門 GitLab 14対応版
今さら聞けない人のためのGit超入門 GitLab 14対応版
 
Version Control System Tutorial バージョン管理システムチュートリアル
Version Control System Tutorial バージョン管理システムチュートリアルVersion Control System Tutorial バージョン管理システムチュートリアル
Version Control System Tutorial バージョン管理システムチュートリアル
 
猫にはわからないGit講座
猫にはわからないGit講座猫にはわからないGit講座
猫にはわからないGit講座
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
 
ソフトウェア工学2023 08 GitHub
ソフトウェア工学2023 08 GitHubソフトウェア工学2023 08 GitHub
ソフトウェア工学2023 08 GitHub
 
Git -分散バージョン管理システム-
Git -分散バージョン管理システム-Git -分散バージョン管理システム-
Git -分散バージョン管理システム-
 
Git 実践入門
Git 実践入門Git 実践入門
Git 実践入門
 
Git
GitGit
Git
 
今さら聞けない人のためのGit超入門
今さら聞けない人のためのGit超入門今さら聞けない人のためのGit超入門
今さら聞けない人のためのGit超入門
 
git 初めの一歩
git 初めの一歩git 初めの一歩
git 初めの一歩
 
Gitの紹介
Gitの紹介Gitの紹介
Gitの紹介
 
Git overview (v 0.96)
Git overview (v 0.96)Git overview (v 0.96)
Git overview (v 0.96)
 
今さら聞けない人のためのgit超入門
今さら聞けない人のためのgit超入門今さら聞けない人のためのgit超入門
今さら聞けない人のためのgit超入門
 
GitLab + Dokku で作る CI/CD 環境
GitLab + Dokku で作る CI/CD 環境GitLab + Dokku で作る CI/CD 環境
GitLab + Dokku で作る CI/CD 環境
 
いいこんぶGitマニュアル
いいこんぶGitマニュアルいいこんぶGitマニュアル
いいこんぶGitマニュアル
 
バージョン管理システムチュートリアル
バージョン管理システムチュートリアルバージョン管理システムチュートリアル
バージョン管理システムチュートリアル
 
今さら聞けない人のためのGitLabの始め方 Ubuntu編
今さら聞けない人のためのGitLabの始め方 Ubuntu編今さら聞けない人のためのGitLabの始め方 Ubuntu編
今さら聞けない人のためのGitLabの始め方 Ubuntu編
 
今さら聞けない人のためのGit超入門 2019/11/21
今さら聞けない人のためのGit超入門 2019/11/21今さら聞けない人のためのGit超入門 2019/11/21
今さら聞けない人のためのGit超入門 2019/11/21
 
Git lev 1-おひとりさま用-
Git lev 1-おひとりさま用-Git lev 1-おひとりさま用-
Git lev 1-おひとりさま用-
 

Último

Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsWSO2
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイスCRI Japan, Inc.
 
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)Hiroshi Tomioka
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Gamesatsushi061452
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルCRI Japan, Inc.
 
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptxsn679259
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video UnderstandingToru Tamaki
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...Toru Tamaki
 

Último (11)

Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 

Git (実践入門編)

  • 1. Git - 実践入門編 (一般公開用) 2012/04/23, DT Corp Naomichi Yamakita
  • 3. 本資料の役割 - 今後始まる新しいプロジェクトは全てGitで運営します - 既存プロジェクトに関しては移行しません(一部を除く) - 本資料はGit利用者(開発者)を対象とした実践向きの内容となってます - プロジェクトを運用する上で、必要最低限の機能を紹介します - 資料に記載されている内容は確実に理解して下さい - 質問があればその場で挙手して下さい - CUIベースで説明を進めます - GUIツール(WindowsのTortoseGit等)の使い方については触れません
  • 4. アジェンダ - 初めに - Gitの概要 - 重要キーワードを理解する - 実践チュートリアル - トラブルシューティング - 終わりに
  • 6. 今までのバージョン管理体制 <Subversion> - 集中型バージョン管理システム - サーバ上に中央リポジトリを持つ - 各開発者はサーバからリソースをチェックアウト・コミットすることで 開発を進めていく - コミットしたら即中央リポジトリに反映される - 履歴の確認、コミット、ブランチの切り替え等はその都度サーバにアク セスする必要がある
  • 7. 新しいバージョン管理体制 <Git> - 分散型バージョン管理システム - 各開発者がローカルリポジトリを持つ - 開発者はローカルリポジトリに変更をコミットし、「プッシュ」を利用 してネットワーク上のリポジトリに更新を反映する - ローカルリポジトリはリモートリポジトリ上の全ての更新履歴、ファイ ル・ディレクトリをミラーリングする - コミット時にスナップショットを保持する(Subversionは差分を保持) - Gitは分散型であるため、「中央サーバ」という概念はない - ただしネットワーク上の特定のリモートリポジトリを中央サーバ (origin)として見立てることは可能
  • 9. リビジョンの管理 - Gitは分散型であるため、リビジョンIDは存在しない - 各開発者のリポジトリで更新が行われるため、「最新のリビジョン」が ない - コミット単位で40bitのハッシュ値(SHA-1)が振られる $ git log --pretty="%h %ai %s" 75e3e7b15a6635bc050d... 2012-04-17 00:37:51 +0900 second commit 697d7ace00a7d0432e7d... 2012-04-17 00:01:58 +0900 first commit
  • 10. リビジョンの管理 - Gitは分散型であるため、リビジョンIDは存在しない - 各開発者のリポジトリで更新が行われるため、「最新のリビジョン」が ない - コミット単位で40bitのハッシュ値(SHA-1)が振られる $ git log --pretty="%h %ai %s" 75e3e7b15a6635bc050d... 2012-04-17 00:37:51 +0900 second commit 697d7ace00a7d0432e7d... 2012-04-17 00:01:58 +0900 first commit コミット時のハッシュ値
  • 11. Gitのメリット - リポジトリ情報をローカルに持つ - 変更履歴の確認やブランチの切り替えでネットワークを参照しないため 高速に動作する - 必ずしもリモートリポジトリを持つ必要がない - いつでもどこでもコミットができる - 中央リポジトリサーバがダウンしても復旧が容易 - ブランチの作成が容易かつ高速 - Subversionより気軽にブランチを切ったりマージすることができる
  • 12. Gitのデメリット - Subversionに比べ敷居が高い - 操作が多く、使用するコマンドも多い - コマンドラインが基本。GUIツールでは全て対応できない - 分散型モデルを理解するまで時間がかかる - リビジョンIDの概念がないため、最新版を把握しにくい - 空ディレクトリを管理できない - 慣例的に.gitignoreファイルを設置しておく - 自由度が高いため、チームで利用する場合は運用ルールを決めないと使いに くい
  • 13. Gitを導入する理由 - Subversionに続くデファクトスタンダード - SubversionからGitに移行したプロジェクト例 - Linux Kernel - Ruby on Rails - Perl5 - Android - GitHubの存在 - Gitリポジトリのホスティングサービスを提供 - Gitで提供されるOSSが増えてきている
  • 14. GItのセットアップ 1/3 - Windows - TortoiseGit + msysgit - http://dtx.co.jp/archives/475 - Mac - brew install git(またはXcodeのインストール) - Linux - yum install git-core
  • 15. GItのセットアップ 2/3 - Gitインストール後にコミット時に使用する名前、メールアドレスを登録する
  • 16. GItのセットアップ 2/3 - Gitインストール後にコミット時に使用する名前、メールアドレスを登録する Name: {your_name} Email: {your_email}
  • 17. GItのセットアップ 3/3 - 開発サーバ上でも同じ設定を登録しておく $ git config user.name "{your_name}" $ git config user.email {your_email} $ cat ~/.gitconfig [user] name = {your_name} email = {your_email} [mergetool] keepBackup = true [core] editor = /usr/bin/vim quotepath = false
  • 18. GItのセットアップ 3/3 - 開発サーバ上でも同じ設定を登録しておく $ git config user.name "{your_name}" $ git config user.email {your_email} $ cat ~/.gitconfig [user] name = {your_name} email = {your_email} [mergetool] keepBackup = true [core] 設定ファイルに名前とメールアドレスが editor = /usr/bin/vim 登録されていることが分かる quotepath = false
  • 20. リポジトリ - ローカルリポジトリ - 開発者のマシンに作成されたローカルリポジトリ。開発者はローカルリ ポジトリに対し、addやcommitを行う - リモートリポジトリ - ネットワーク越しにあるマシン上(サーバとは限らない)のリポジト リ。開発者はローカルリポジトリの内容をpushして送信したり、pullで ローカルとの差分を取得・マージする - 概念的にはSubversionのcommit、updateに近い
  • 21. ブランチ - ローカルブランチ - ローカルリポジトリで管理されるブランチ。git initで新しいリポジト リを作成した場合、デフォルトのブランチ名はmasterとなる。 masterには常に最新のソースをコミットする。Subversionで言うと ころのtrunkと似ている - リモートブランチ - リモートリポジトリ上のブランチ。git clone時はmasterブランチが チェックアウトされる - リモートトラッキングブランチ(追跡ブランチ) - 現在有効なリモートブランチと繋がりを持つローカルブランチ
  • 22. HEAD - 現在作業しているローカルブランチへのポインタ - 現在のブランチにおける1つ手前のコミット状態 - HEAD^ - 現在のブランチにおける2つ前のコミット状態 - HEAD^^
  • 23. インデックス 1/2 - 次のコミット対象となるファイルの一時領域 - 新規作成したファイルは必ずインデックスに登録が必要 - git add {file_name} - ファイルを更新(変更・削除・リネーム等)した場合もインデックスへの再 登録が必要 - 2回目以降はコミットと同時にadd指定することも可能 - git commit -m {commit_message} -a {file_name} - インデックスに登録された状態を「ステージ」と言う
  • 24. インデックス 2/2 - インデックスはSubversionにはない考え方 - インデックスは何のためにあるのか? - 次回のコミットに含めたくないファイルを除外することができる
  • 25. その他 - ワーキングツリー - ローカルリポジトリにおける実際の作業場所。Subversionの「ワーキン グコピー」と同じ - コミット - ローカルリポジトリへの更新の反映 - スナップショットが作成されるタイミング - プッシュ - ローカルリポジトリの内容をリモートリポジトリに反映する - プル - リモートリポジトリの内容をローカルリポジトリに反映する
  • 27. リポジトリを作成する <git init> 1/2 - 新規リポジトリの作成 $ git init gitrep Initialized empty Git repository in /Users/naomichi/ gitrep/.git/ $ cd gitrep/ $ ls -la total 0 drwxr-xr-x 3 naomichi staff 102 4 16 23:21:44 2012 . drwxr-xr-x+ 41 naomichi staff 1394 4 16 23:21:44 2012 .. drwxr-xr-x 10 naomichi staff 340 4 16 23:21:44 2012 .git
  • 28. リポジトリを作成する <git init> 1/2 - 新規リポジトリの作成 $ git init gitrep Initialized empty Git repository in /Users/naomichi/ gitrep/.git/ $ cd gitrep/ $ ls -la total 0 drwxr-xr-x 3 naomichi staff 102 4 16 23:21:44 2012 . drwxr-xr-x+ 41 naomichi staff 1394 4 16 23:21:44 2012 .. drwxr-xr-x 10 naomichi staff 340 4 16 23:21:44 2012 .git .gitはルートディレクトリのみに作成さ れる。.gitはGitのメタ情報を管理する
  • 29. リポジトリを作成する <git clone> 2/2 - リモートリポジトリのクローンを作成 $ git clone git@{fqdn}:test gitrep Cloning into gitrep... remote: Counting objects: 79, done. remote: Compressing objects: 100% (44/44), done. remote: Total 79 (delta 4), reused 0 (delta 0) Receiving objects: 100% (79/79), 6.09 KiB, done. Resolving deltas: 100% (4/4), done. [naomichi: workgit]$ ls -la gitrep/ total 0 drwxr-xr-x 3 naomichi staff 102 4 16 23:21:44 2012 . drwxr-xr-x+ 41 naomichi staff 1394 4 16 23:21:44 2012 .. drwxr-xr-x 10 naomichi staff 340 4 16 23:21:44 2012 .git
  • 30. リポジトリを作成する <git clone> 2/2 - リモートリポジトリのクローンを作成 $ git clone git@{fqdn}:test gitrep Cloning into gitrep... remote: Counting objects: 79, done. remote: Compressing objects: 100% (44/44), done. remote: Total 79 (delta 4), reused 0 (delta 0) Receiving objects: 100% (79/79), 6.09 KiB, done. Resolving deltas: 100% (4/4), done. [naomichi: workgit]$ ls -la gitrep/ git clone {repository_path}:{url} {create_directory} total 0 drwxr-xr-x 3 naomichi staff 102 4 16 23:21:44 2012 . drwxr-xr-x+ 41 naomichi staff 1394 4 16 23:21:44 2012 .. drwxr-xr-x 10 naomichi staff 340 4 16 23:21:44 2012 .git
  • 31. ファイルをインデックスに登録する <git add> - 単体ファイルの登録 $ touch hello $ git add hello - 複数ファイルの登録 $ mkdir foo $ touch foo/bar $ touch foo/baz $ git add foo - 全てのファイルを登録 $ git add .
  • 32. ファイルをインデックスに登録する <git add> - 単体ファイルの登録 $ touch hello $ git add hello - 複数ファイルの登録 ステージ状態 $ mkdir foo $ touch foo/bar $ touch foo/baz $ git add foo - 全てのファイルを登録 $ git add .
  • 33. ファイルをコミットする <git commit> 1/2 - 単体ファイルのコミット $ touch hello $ git add hello $ git commit -m "first commit" [master 697d7ac] first commit 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 hello - 複数ファイルのコミット $ mkdir foo $ touch foo/bar $ touch foo/baz $ git add foo $ git commit -m "first commit" [master 1f615ff] first commit 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 foo/bar create mode 100644 foo/baz
  • 34. ファイルをコミットする <git commit> 1/2 - 単体ファイルのコミット Gitではコメント入力が必須 $ touch hello $ git add hello $ git commit -m "first commit" [master 697d7ac] first commit 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 hello コミットハッシュの先頭文字 - 複数ファイルのコミット $ mkdir foo $ touch foo/bar $ touch foo/baz $ git add foo $ git commit -m "first commit" [master 1f615ff] first commit 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 foo/bar create mode 100644 foo/baz
  • 35. ファイルをコミットする <git commit> 1/2 - 単体ファイルのコミット Gitではコメント入力が必須 $ touch hello $ git add hello $ git commit -m "first commit" [master 697d7ac] first commit 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 hello コミットハッシュの先頭文字 - 複数ファイルのコミット $ mkdir foo $ touch foo/bar $ touch foo/baz $ git add foo $ git commit -m "first commit" [master 1f615ff] first commit 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 foo/bar git -m first commit -a fooで代用可能 create mode 100644 foo/baz
  • 36. ファイルをコミットする <git commit> 2/2 - ファイル変更後の再コミット $ echo 'this is bar' > foo/bar $ echo 'this is baz' > foo/baz $ git add foo/bar $ git commit # On branch master # Your branch is ahead of 'origin/master' by 7 commits. # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: foo/bar #
  • 37. ファイルをコミットする <git commit> 2/2 - ファイル変更後の再コミット $ echo 'this is bar' > foo/bar $ echo 'this is baz' > foo/baz $ git add foo/bar $ git commit # On branch master # Your branch is barのみインデックスに登録 ahead of 'origin/master' by 7 commits. # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: foo/bar # bazはコミット対象外
  • 38. コミットの詳細を確認する <git show> - 特定のコミットで変更されたファイル一覧を取得 $ touch file_1 file_2 file_3 $ git add . $ git commit -m "first commit" $ git log commit dd3ba389a19e85265bd5d382733a86900a56ffe8 ... $ git show --name-only dd3ba389a19e85265bd5d382733a86900a56ffe8 commit dd3ba389a19e85265bd5d382733a86900a56ffe8 Author: {your_name} <{your_email}> Date: Sun Apr 22 01:41:03 2012 +0900 first commit file_1 file_2 file_3
  • 39. コミットの詳細を確認する <git show> - 特定のコミットで変更されたファイル一覧を取得 $ touch file_1 file_2 file_3 $ git add . コミットハッシュ値 $ git commit -m "first commit" $ git log commit dd3ba389a19e85265bd5d382733a86900a56ffe8 ... $ git show --name-only dd3ba389a19e85265bd5d382733a86900a56ffe8 commit dd3ba389a19e85265bd5d382733a86900a56ffe8 Author: {your_name} <{your_email}> Date: Sun Apr 22 01:41:03 2012 +0900 dd3ba...のコミット内容を確認 first commit file_1 file_2 file_3 dd3ba...でコミットされたファイルの一覧
  • 40. リモートリポジトリへの反映 <git push> - インデックスに登録されているファイルをプッシュする $ touch hello $ git add . $ git commit -m "first commit" [master 4ccbdef] first commit 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 hello $ git push Counting objects: 28, done. Delta compression using up to 4 threads. Compressing objects: 100% (20/20), done. Writing objects: 100% (27/27), 2.14 KiB, done. Total 27 (delta 3), reused 2 (delta 0) To git@{fqdn}:test a22beb4..4ccbdef master -> master
  • 41. リモートリポジトリへの反映 <git push> - インデックスに登録されているファイルをプッシュする $ touch hello $ git add . $ git commit -m "first commit" [master 4ccbdef] first commit 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 hello $ git push Counting objects: 28, done. Delta compression using up to 4 threads. Compressing objects: 100% (20/20), done. Writing objects: 100% (27/27), 2.14 KiB, done. Total 27 (delta 3), reused 2 (delta 0) To git@{fqdn}:test a22beb4..4ccbdef master -> master push成功通知
  • 42. リモートリポジトリから差分を取得 <git pull> - 他のリポジトリの変更点をローカルリポジトリにマージする $ git pull remote: Counting objects: 5, done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From {fqdn}:test 4ccbdef..dafbd21 master -> origin/master Updating 4ccbdef..dafbd21 Fast-forward hello | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
  • 43. リモートリポジトリから差分を取得 <git pull> - 他のリポジトリの変更点をローカルリポジトリにマージする $ git pull remote: Counting objects: 5, done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From {fqdn}:test 4ccbdef..dafbd21 master -> origin/master Updating 4ccbdef..dafbd21 Fast-forward hello | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) pull成功通知
  • 44. 変更が加えられたファイルを表示 <git status> - ワーキングツリーやインデックス、リポジトリの状態を分類して表示する $ touch a b c d $ git add b c d $ git commit -m "c,d commited" c d $ echo 'REWRITE' > d $ git status # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: b # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: d # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # a
  • 45. 変更が加えられたファイルを表示 <git status> - ワーキングツリーやインデックス、リポジトリの状態を分類して表示する $ touch a b c d $ git add b c d $ git commit -m "c,d commited"ステージ状態(コミット待ち) c d $ echo 'REWRITE' > d $ git status # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: b # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) 修正状態(ステージ待ち) # # modified: d # # Untracked files: # (use "git add <file>..." to include in what will be committed) # 未追跡状態 # a
  • 46. Gitにおけるファイルのライフサイクル - Untracked、Unmodified、Modified、Stagedの違いを理解する
  • 47. コミットログの表示 <git log> - 最新コミット(HEAD)からたどることができるログを表示する $ git log commit e738db944c0a03b130b2df628213449f6597c08e Author: {your_name} <{your_email}> Date: Thu Apr 19 12:30:47 2012 +0900 third commit commit 22a17381b6a514b0eaa511fa0c76edb7ba0bc46b Author: {your_name} <{your_email}> Date: Thu Apr 19 12:16:27 2012 +0900 second commit commit 22a17381b6a514b0eaa511fa0c76edb7ba0bc46b Author: {your_name} <{your_email}> Date: Thu Apr 19 12:16:27 2012 +0900 first commit ...
  • 48. コミットログの表示 <git log> - 最新コミット(HEAD)からたどることができるログを表示する 3回目のコミットログ $ git log commit e738db944c0a03b130b2df628213449f6597c08e Author: {your_name} <{your_email}> Date: Thu Apr 19 12:30:47 2012 +0900 2回目のコミットログ third commit commit 22a17381b6a514b0eaa511fa0c76edb7ba0bc46b Author: {your_name} <{your_email}> Date: Thu Apr 19 12:16:27 2012 +0900 1回目のコミットログ second commit commit 22a17381b6a514b0eaa511fa0c76edb7ba0bc46b Author: {your_name} <{your_email}> Date: Thu Apr 19 12:16:27 2012 +0900 first commit ...
  • 49. ブランチ <git branch> 1/2 - 現在のブランチを確認する $ git branch * master - 新しいブランチを作成する $ git branch new_branch $ git branch * master new_branch - 新しいブランチをチェックアウトする $ git checkout new_branch Switched to branch 'new_branch' $ git branch master * new_branch
  • 50. ブランチ <git branch> 1/2 - 現在のブランチを確認する *(アスタリスク)はカレントブランチを示す $ git branch * master - 新しいブランチを作成する $ git branch new_branch $ git branch * master new_branch - 新しいブランチをチェックアウトする $ git checkout new_branch Switched to branch 'new_branch' $ git branch master * new_branch
  • 51. ブランチ <git branch> 1/2 - 現在のブランチを確認する *(アスタリスク)はカレントブランチを示す $ git branch * master - 新しいブランチを作成する ブランチ作成後もカレントブランチはmasterのまま $ git branch new_branch $ git branch * master new_branch - 新しいブランチをチェックアウトする $ git checkout new_branch Switched to branch 'new_branch' $ git branch master * new_branch
  • 52. ブランチ <git branch> 1/2 - 現在のブランチを確認する *(アスタリスク)はカレントブランチを示す $ git branch * master - 新しいブランチを作成する ブランチ作成後もカレントブランチはmasterのまま $ git branch new_branch $ git branch * master new_branch - 新しいブランチをチェックアウトする $ git checkout new_branch Switched to branch 'new_branch' カレントブランチが切り替わる $ git branch master * new_branch
  • 53. ブランチ <git branch> 2/2 - 新しいブランチをプッシュする $ git push origin new_branch Counting objects: 19, done. Delta compression using up to 4 threads. Compressing objects: 100% (14/14), done. Writing objects: 100% (17/17), 1.45 KiB, done. Total 17 (delta 5), reused 1 (delta 0) To git@{fqdn}:test * [new branch] new_branch -> new_branch - リモートを含めた全てのブランチを確認する $ git branch -a master * new_branch remotes/origin/HEAD -> origin/master remotes/origin/master remotes/origin/new_branch
  • 54. ブランチ <git branch> 2/2 - 新しいブランチをプッシュする リモートブランチの作成成功通知 $ git push origin new_branch Counting objects: 19, done. Delta compression using up to 4 threads. Compressing objects: 100% (14/14), done. Writing objects: 100% (17/17), 1.45 KiB, done. Total 17 (delta 5), reused 1 (delta 0) To git@{fqdn}:test * [new branch] new_branch -> new_branch - リモートを含めた全てのブランチを確認する $ git branch -a master * new_branch remotes/origin/HEAD -> origin/master remotes/origin/master remotes/origin/new_branch
  • 55. ブランチ <git branch> 2/2 - 新しいブランチをプッシュする リモートブランチの作成成功通知 $ git push origin new_branch Counting objects: 19, done. Delta compression using up to 4 threads. Compressing objects: 100% (14/14), done. Writing objects: 100% (17/17), 1.45 KiB, done. Total 17 (delta 5), reused 1 (delta 0) To git@{fqdn}:test * [new branch] new_branch -> new_branch - リモートを含めた全てのブランチを確認する $ git branch -a master * new_branch remotes/origin/HEAD -> origin/master remotes/origin/master remotes/origin/new_branch リモートにnew_branchが作成されていることがわかる
  • 56. 差分の比較 1/3 - git diff - ワーキングツリーとインデックスの差分を比較 - ステージングされていないファイルは比較できない - インデックスにファイルが登録された状態で、更に同じファイルを更新 した場合に使う - インデックス登録とコミットを同時に行う場合はあまり使わない
  • 57. 差分の比較 2/3 - git diff --cached - HEADとインデックスの差分を表示する - インデックスに登録されたファイルをコミットする前に使用する
  • 58. 差分の比較 3/3 - git diff HEAD - HEADとワーキングツリーの比較 - 前回コミットからどれくらい編集されているか調べる際に使用する - HEAD の部分はHEAD^やコミットのハッシュ値を指定することも可能
  • 59. 一部のディレクトリのみチェックアウト - GitはSubversionのように一部のディレクトリのみチェックアウトすること ができない - Git 1.7から導入されたSprase checkout機能を使う - Sparse checkout example in git 1.7.0 $ git clone git@{fqdn}:common Cloning into common... remote: Counting objects: 2134, done. remote: Compressing objects: 100% (1173/1173), done. commremote: Total 2134 (delta 906), reused 2125 (delta 903) Receiving objects: 100% (2134/2134), 24.22 MiB |次回以降はgit pullでproject 579 KiB/s, done. Resolving deltas: 100% (906/906), done.) のみがチェックアウトされる $ cd common/ $ git config core.sparsecheckout true $ echo project/ > .git/info/sparse-checkout $ git read-tree -m -u HEAD
  • 60. 特定のファイル・ディレクトリをコミット対象外にする - 特定のファイルをコミット対象外にする $ touch a b $ echo 'b' > .gitignore $ git add . $ git commit -m "ignore commit" [master 2bfa6b1] ignore commit 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 .gitignore - 特定のディレクトリの内容をコミット対象外とする $ mkdir logs $ touch logs/a logs/b logs/c $ echo 'logs/' > .gitignore $ echo '!.gitignore' >> .gitignore $ touch logs/.gitignore $ git add . $ git commit -m "ignore commit" [master 9a9a128] ignore commit 0 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 a
  • 61. 特定のファイル・ディレクトリをコミット対象外にする - 特定のファイルをコミット対象外にする $ touch a b $ echo 'b' > .gitignore ファイルbはコミットされない $ git add . $ git commit -m "ignore commit" [master 2bfa6b1] ignore commit 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 .gitignore - 特定のディレクトリの内容をコミット対象外とする $ mkdir logs $ touch logs/a logs/b logs/c $ echo 'logs/' > .gitignore $ echo '!.gitignore' >> .gitignore $ touch logs/.gitignore $ git add . $ git commit -m "ignore commit" [master 9a9a128] ignore commit 0 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 a
  • 62. 特定のファイル・ディレクトリをコミット対象外にする - 特定のファイルをコミット対象外にする $ touch a b $ echo 'b' > .gitignore ファイルbはコミットされない $ git add . $ git commit -m "ignore commit" [master 2bfa6b1] ignore commit 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 .gitignore - 特定のディレクトリの内容をコミット対象外とする 「!」は否定 $ mkdir logs logs下は対象外とするが、.gitignoreはコミット対象とする $ touch logs/a logs/b logs/c $ echo 'logs/' > .gitignore $ echo '!.gitignore' >> .gitignore $ touch logs/.gitignore $ git add . $ git commit -m "ignore commit" Gitは空ディレクトリを削除してしまうので、 [master 9a9a128] ignore commit ダミーファイルを作成しておく 0 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 a
  • 63. コミットメールの見方 - プロジェクトの開発関係者にメールが通知される This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "mars". The branch, 1.10 has been updated via f46534818a5432b212e2a24c9d00f706ba7df5f4 (commit) from 3759217a665beabb6f17a81c8e3b26b5c9c02920 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit f46534818a5432b212e2a24c9d00f706ba7df5f4 Author: {your_name} <{your_email}> Date: Thu Apr 19 13:39:12 2012 +0900 first commit ----------------------------------------------------------------------- Summary of changes: VERSION | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) hooks/post-receive -- mars
  • 64. コミットメールの見方 - プロジェクトの開発関係者にメールが通知される This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "mars". The branch, 1.10 has been updated via f46534818a5432b212e2a24c9d00f706ba7df5f4 (commit) from 3759217a665beabb6f17a81c8e3b26b5c9c02920 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list ブランチ情報、コミットハッシュ情報 those revisions in full, below. - Log ----------------------------------------------------------------- commit f46534818a5432b212e2a24c9d00f706ba7df5f4 Author: {your_name} <{your_email}> Date: Thu Apr 19 13:39:12 2012 +0900 first commit ----------------------------------------------------------------------- Summary of changes: VERSION | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) hooks/post-receive -- mars
  • 65. コミットメールの見方 - プロジェクトの開発関係者にメールが通知される This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "mars". The branch, 1.10 has been updated via f46534818a5432b212e2a24c9d00f706ba7df5f4 (commit) from 3759217a665beabb6f17a81c8e3b26b5c9c02920 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list ブランチ情報、コミットハッシュ情報 those revisions in full, below. - Log ----------------------------------------------------------------- commit f46534818a5432b212e2a24c9d00f706ba7df5f4 Author: {your_name} <{your_email}> Date: Thu Apr 19 13:39:12 2012 +0900 コミットログ情報 first commit ----------------------------------------------------------------------- Summary of changes: VERSION | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) hooks/post-receive -- mars
  • 66. コミットメールの見方 - プロジェクトの開発関係者にメールが通知される This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "mars". The branch, 1.10 has been updated via f46534818a5432b212e2a24c9d00f706ba7df5f4 (commit) from 3759217a665beabb6f17a81c8e3b26b5c9c02920 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list ブランチ情報、コミットハッシュ情報 those revisions in full, below. - Log ----------------------------------------------------------------- commit f46534818a5432b212e2a24c9d00f706ba7df5f4 Author: {your_name} <{your_email}> Date: Thu Apr 19 13:39:12 2012 +0900 コミットログ情報 first commit ----------------------------------------------------------------------- Summary of changes: VERSION | 2 +- 変更されたファイルの情報 1 files changed, 1 insertions(+), 1 deletions(-) hooks/post-receive -- mars
  • 68. ファイルが一方にしか存在しない 1/3 - テストケース 1. リポジトリAでa∼cのファイルを作成後にプッシュ 2. リポジトリBでプルする 3. リポジトリAでdのファイルを作成後にプッシュ 4. リポジトリBでプッシュする 5. この後何が起こるか?
  • 69. ファイルが一方にしか存在しない 2/3 - リポジトリBでプッシュした直後のレスポンス $ git push To git@{fqdn}:test ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'git@{fqdn}:test' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details.
  • 70. ファイルが一方にしか存在しない 2/3 - リポジトリBでプッシュした直後のレスポンス $ git push To git@{fqdn}:test ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'git@{fqdn}:test' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details. non-fast-forwardとなり、プッシュに失敗する
  • 71. ファイルが一方にしか存在しない 3/3 - 対策:リモートリポジトリの差分を取得後にプッシュする $ git pull remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. remote: Total 2 (delta 1), reused 0 (delta 0) Unpacking objects: 100% (2/2), done. From {fqdn}:test 05e23a1..ae8a6a6 master -> origin/master Merge made by recursive. 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 d $ git push Counting objects: 14, done. Delta compression using up to 4 threads. Compressing objects: 100% (7/7), done. Writing objects: 100% (9/9), 958 bytes, done. Total 9 (delta 2), reused 1 (delta 0) To git@{fqdn}:test ae8a6a6..53fe5ce master -> master
  • 72. ファイルが一方にしか存在しない 3/3 - 対策:リモートリポジトリの差分を取得後にプッシュする $ git pull remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. remote: Total 2 (delta 1), reused 0 (delta 0) Unpacking objects: 100% (2/2), done. From {fqdn}:test 05e23a1..ae8a6a6 master -> origin/master Merge made by recursive. 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 d $ git push push成功通知 Counting objects: 14, done. Delta compression using up to 4 threads. Compressing objects: 100% (7/7), done. Writing objects: 100% (9/9), 958 bytes, done. Total 9 (delta 2), reused 1 (delta 0) To git@{fqdn}:test ae8a6a6..53fe5ce master -> master
  • 73. ファイルの競合 1/3 - テストケース 1. リポジトリAでhelloファイルを「WRITE FROM REP-A」として保存 2. helloをコミットしてリモートにプッシュする 3. リポジトリBでhelloファイルを「WRITE FROM REP-B」として保存 4. helloをコミットしてリモートにプッシュする 5. この後何が起こるか?
  • 74. ファイルの競合 2/3 - リポジトリBでhelloをプッシュした直後のレスポンス $ git push To git@{fqdn}:test ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'git@{fqdn}:test' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details.
  • 75. ファイルの競合 2/3 - リポジトリBでhelloをプッシュした直後のレスポンス $ git push To git@{fqdn}:test ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'git@{fqdn}:test' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details. non-fast-forwardとなり、プッシュに失敗する
  • 76. ファイルの競合 3/3 - 対策:他のリポジトリの変更を取得し、差分をチェックする $ git fetch $ git diff FETCH_HEAD diff --git a/hello b/hello index 10cf535..843c591 100644 --- a/hello +++ b/hello @@ -1 +1 @@ -w-200 +REWRITE B - git fetch - 他のリポジトリの変更をFETCH_HEADに格納する - git diff FETCH_HEAD - ローカルとリモートリポジトリの差分を取得
  • 77. ファイルの競合 3/3 - 対策:他のリポジトリの変更を取得し、差分をチェックする $ git fetch $ git diff FETCH_HEAD diff --git a/hello b/hello index 10cf535..843c591 100644 --- a/hello +++ b/hello @@ -1 +1 @@ -w-200 +REWRITE B - git fetch ファイルの差分が表示される - 他のリポジトリの変更をFETCH_HEADに格納する - git diff FETCH_HEAD - ローカルとリモートリポジトリの差分を取得
  • 78. コンフリクトファイルの修正 1/3 - テストケース 1. リポジトリAでhelloファイルを「WRITE FROM REP-A」として保存 2. helloをコミットしてリモートにプッシュする 3. リポジトリBでhelloファイルを「WRITE FROM REP-B」として保存 4. helloをコミット 5. リポジトリBでリモートの反映をプルする 6. この後何が起こるか?
  • 79. コンフリクトファイルの修正 2/3 - リポジトリBでプルした直後のレスポンス $ git pull ls remote: Counting objects: 5, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 1), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From {fqdn}:test 186584c..22a1738 master -> origin/master Auto-merging hello CONFLICT (content): Merge conflict in hello Automatic merge failed; fix conflicts and then commit the result.
  • 80. コンフリクトファイルの修正 2/3 - リポジトリBでプルした直後のレスポンス $ git pull ls remote: Counting objects: 5, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 1), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From {fqdn}:test 186584c..22a1738 master -> origin/master Auto-merging hello CONFLICT (content): Merge conflict in hello Automatic merge failed; fix conflicts and then commit the result. マージ中にコンフリクトが発生
  • 81. コンフリクトファイルの修正 3/3 - 対策:変更が加えられたファイルの一覧を表示する $ git status # On branch master # Your branch and 'origin/master' have diverged, # and have 1 and 1 different commit(s) each, respectively. # # Unmerged paths: # (use "git add/rm <file>..." as appropriate to mark resolution) # # both modified: hello # $ cat hello <<<<<<< HEAD WRITE FROM REP-B ======= WRITE FROM REP-A >>>>>>> 22a17381b6a514b0eaa511fa0c76edb7ba0bc46b
  • 82. コンフリクトファイルの修正 3/3 - 対策:変更が加えられたファイルの一覧を表示する $ git status # On branch master マージに失敗したファイルの一覧 # Your branch and 'origin/master' have diverged, # and have 1 and 1 different commit(s) each, respectively. # # Unmerged paths: # (use "git add/rm <file>..." as appropriate to mark resolution) # # both modified: hello # $ cat hello <<<<<<< HEAD WRITE FROM REP-B ======= WRITE FROM REP-A >>>>>>> 22a17381b6a514b0eaa511fa0c76edb7ba0bc46b
  • 84. Gitの運用フロー - Gitは自由度が高いため、運用フローを決めないと使いにくい - 運用モデルの1つに「A successful Git branching model」がある - http://nvie.com/posts/a-successful-git-branching-model/ - 安定ブランチ(master)、開発ブランチ(develop)を主軸とし、ホッ トフィックスやリリースの度にサポートブランチを作成・破棄していく - このモデルをサポートするgit-flowというプラグインがある
  • 85. 参考資料 - Pro Git(En/Ja) - http://progit.org/ebook/progit.pdf - Gitによるバージョン管理

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. &amp;#x30FB;&amp;#x5DE6;&amp;#x306E;&amp;#x56F3;&amp;#x306B;&amp;#x3064;&amp;#x3044;&amp;#x3066;&amp;#x88DC;&amp;#x8DB3;\nGit&amp;#x306F;&amp;#x6982;&amp;#x5FF5;&amp;#x4E0A;&amp;#x3001;&amp;#x4E2D;&amp;#x592E;&amp;#x30EA;&amp;#x30DD;&amp;#x30B8;&amp;#x30C8;&amp;#x30EA;&amp;#x306F;&amp;#x306A;&amp;#x3044;&amp;#x304C;&amp;#x3001;&amp;#x30DE;&amp;#x30B9;&amp;#x30BF;&amp;#x30FC;&amp;#x30EA;&amp;#x30DD;&amp;#x30B8;&amp;#x30C8;&amp;#x30EA;&amp;#xFF08;origin&amp;#xFF09;&amp;#x3068;&amp;#x3057;&amp;#x3066;&amp;#x4E00;&amp;#x53F0;&amp;#x898B;&amp;#x7ACB;&amp;#x3066;&amp;#x308B;\n&amp;#x305D;&amp;#x308C;&amp;#x305E;&amp;#x308C;&amp;#x306E;&amp;#x958B;&amp;#x767A;&amp;#x8005;&amp;#x306F;origin&amp;#x304B;&amp;#x3089;push&amp;#x307E;&amp;#x305F;&amp;#x306F;pull&amp;#x3092;&amp;#x884C;&amp;#x3046;\n&amp;#x56F3;&amp;#x306E;&amp;#x3088;&amp;#x3046;&amp;#x306B;Alice&amp;#x3001;Bob&amp;#x3001;David&amp;#x3001;Clair&amp;#x30C1;&amp;#x30FC;&amp;#x30E0;&amp;#x304C;&amp;#x3042;&amp;#x308B;&amp;#x5834;&amp;#x5408;&amp;#x3001;&amp;#x5404;&amp;#x30C1;&amp;#x30FC;&amp;#x30E0;&amp;#x9593;&amp;#x3067;origin&amp;#x306B;push&amp;#x3059;&amp;#x308B;&amp;#x524D;&amp;#x306B;&amp;#x4E92;&amp;#x3044;&amp;#x306E;&amp;#x30EA;&amp;#x30DD;&amp;#x30B8;&amp;#x30C8;&amp;#x30EA;&amp;#x3067;push/pull&amp;#x3059;&amp;#x308B;&amp;#x5229;&amp;#x7528;&amp;#x65B9;&amp;#x6CD5;&amp;#x3082;&amp;#x3042;&amp;#x308B;&amp;#xFF08;Alice&amp;#x304B;&amp;#x3089;&amp;#x898B;&amp;#x3066;Bob&amp;#x3084;David&amp;#x306F;&amp;#x30EA;&amp;#x30E2;&amp;#x30FC;&amp;#x30C8;&amp;#x30EA;&amp;#x30DD;&amp;#x30B8;&amp;#x30C8;&amp;#x30EA;&amp;#xFF09;\n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. &amp;#x30FB;&amp;#x30EA;&amp;#x30E2;&amp;#x30FC;&amp;#x30C8;&amp;#x30C8;&amp;#x30E9;&amp;#x30C3;&amp;#x30AD;&amp;#x30F3;&amp;#x30B0;&amp;#x30D6;&amp;#x30E9;&amp;#x30F3;&amp;#x30C1;\n&amp;#x3000;git push&amp;#x3001;git pull&amp;#x3057;&amp;#x305F;&amp;#x969B;&amp;#x3001;&amp;#x9069;&amp;#x3057;&amp;#x305F;&amp;#x30D6;&amp;#x30E9;&amp;#x30F3;&amp;#x30C1;&amp;#x306B;&amp;#x53CD;&amp;#x6620;&amp;#x3055;&amp;#x308C;&amp;#x308B;&amp;#x306E;&amp;#x306F;&amp;#x30C8;&amp;#x30E9;&amp;#x30C3;&amp;#x30AD;&amp;#x30F3;&amp;#x30B0;&amp;#x30D6;&amp;#x30E9;&amp;#x30F3;&amp;#x30C1;&amp;#x306E;&amp;#x304A;&amp;#x304B;&amp;#x3052;\n
  19. &amp;#x30FB;&amp;#x30ED;&amp;#x30FC;&amp;#x30AB;&amp;#x30EB;&amp;#x30D6;&amp;#x30E9;&amp;#x30F3;&amp;#x30C1;&amp;#x306F;&amp;#x8907;&amp;#x6570;&amp;#x5B58;&amp;#x5728;&amp;#x3059;&amp;#x308B;&amp;#x5834;&amp;#x5408;&amp;#x304C;&amp;#x3042;&amp;#x308B;&amp;#x304C;&amp;#x3001;&amp;#x73FE;&amp;#x5728;&amp;#x3069;&amp;#x306E;&amp;#x30D6;&amp;#x30E9;&amp;#x30F3;&amp;#x30C1;&amp;#x3067;&amp;#x4F5C;&amp;#x696D;&amp;#x3057;&amp;#x3066;&amp;#x3044;&amp;#x308B;&amp;#x304B;&amp;#x3092;&amp;#x628A;&amp;#x63E1;&amp;#x3059;&amp;#x308B;&amp;#x305F;&amp;#x3081;&amp;#x306B;&amp;#x7528;&amp;#x3044;&amp;#x3089;&amp;#x308C;&amp;#x308B;&amp;#x306E;&amp;#x304C;HEAD\n&amp;#x30FB;&amp;#x753B;&amp;#x9762;&amp;#x4E2D;&amp;#x592E;&amp;#x306E;&amp;#x56F3;&amp;#x3002;git checkout&amp;#x3059;&amp;#x308B;&amp;#x3053;&amp;#x3068;&amp;#x3067;&amp;#x30ED;&amp;#x30FC;&amp;#x30AB;&amp;#x30EB;&amp;#x30D6;&amp;#x30E9;&amp;#x30F3;&amp;#x30C1;&amp;#x3092;&amp;#x5207;&amp;#x308A;&amp;#x66FF;&amp;#x3048;&amp;#x308B;&amp;#x3053;&amp;#x3068;&amp;#x304C;&amp;#x3067;&amp;#x304D;&amp;#x308B;\n&amp;#x30FB;&amp;#x753B;&amp;#x9762;&amp;#x4E0B;&amp;#x306E;&amp;#x56F3;&amp;#x3002;add commit&amp;#x306F;master&amp;#x3001;stable&amp;#x306B;&amp;#x306F;&amp;#x53CD;&amp;#x6620;&amp;#x3055;&amp;#x308C;&amp;#x306A;&amp;#x3044;&amp;#x70B9;&amp;#x306B;&amp;#x6CE8;&amp;#x610F;\n&amp;#x30FB;&amp;#x753B;&amp;#x9762;&amp;#x4E0B;&amp;#x306E;&amp;#x56F3;&amp;#x3002;old&amp;#x306E;&amp;#x53F3;&amp;#x6A2A;&amp;#x306B;&amp;#x25CF;&amp;#x304C;&amp;#x8FFD;&amp;#x52A0;&amp;#x3055;&amp;#x308C;&amp;#x305F;&amp;#x5834;&amp;#x5408;&amp;#x3001;HEAD^&amp;#x306F;&amp;#x3069;&amp;#x3053;&amp;#x3092;&amp;#x6307;&amp;#x3059;?&amp;#xFF08;&amp;#x7B54;&amp;#x3048;&amp;#x306F;old&amp;#xFF09;\n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. &amp;#x30FB;git clone&amp;#x306F;svn checkout&amp;#x306B;&amp;#x76F8;&amp;#x5F53;&amp;#x3059;&amp;#x308B;\n
  26. &amp;#x30FB;add&amp;#x6642;&amp;#x306B;&amp;#x306F;&amp;#x7279;&amp;#x306B;&amp;#x30E1;&amp;#x30C3;&amp;#x30BB;&amp;#x30FC;&amp;#x30B8;&amp;#x304C;&amp;#x8868;&amp;#x793A;&amp;#x3055;&amp;#x308C;&amp;#x306A;&amp;#x3044;\n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. &amp;#x30FB;&amp;#x30AA;&amp;#x30D7;&amp;#x30B7;&amp;#x30E7;&amp;#x30F3;&amp;#x3092;&amp;#x4ED8;&amp;#x3051;&amp;#x308B;&amp;#x3053;&amp;#x3068;&amp;#x3067;&amp;#x30ED;&amp;#x30B0;&amp;#x306E;&amp;#x8868;&amp;#x793A;&amp;#x5F62;&amp;#x5F0F;&amp;#x306F;&amp;#x30AB;&amp;#x30B9;&amp;#x30BF;&amp;#x30DE;&amp;#x30A4;&amp;#x30BA;&amp;#x53EF;&amp;#x80FD;\n
  36. &amp;#x30FB;&amp;#x30D6;&amp;#x30E9;&amp;#x30F3;&amp;#x30C1;&amp;#x3092;&amp;#x5207;&amp;#x308A;&amp;#x66FF;&amp;#x3048;&amp;#x305F;&amp;#x5834;&amp;#x5408;&amp;#x3001;&amp;#x65E2;&amp;#x5B58;&amp;#x306E;&amp;#x30D6;&amp;#x30E9;&amp;#x30F3;&amp;#x30C1;&amp;#x306E;&amp;#x5185;&amp;#x5BB9;&amp;#x306F;&amp;#x65B0;&amp;#x3057;&amp;#x3044;&amp;#x5185;&amp;#x5BB9;&amp;#x306B;&amp;#x7F6E;&amp;#x304D;&amp;#x63DB;&amp;#x3048;&amp;#x3089;&amp;#x308C;&amp;#x308B;&amp;#x306E;&amp;#x3067;&amp;#x6CE8;&amp;#x610F;&amp;#x304C;&amp;#x5FC5;&amp;#x8981;\n&amp;#x30FB;Subversion&amp;#x306E;&amp;#x3088;&amp;#x3046;&amp;#x306B;&amp;#x300C;&amp;#x30D6;&amp;#x30E9;&amp;#x30F3;&amp;#x30C1;=&amp;#x30C7;&amp;#x30A3;&amp;#x30EC;&amp;#x30AF;&amp;#x30C8;&amp;#x30EA;&amp;#x300D;&amp;#x3068;&amp;#x3044;&amp;#x3046;&amp;#x6982;&amp;#x5FF5;&amp;#x3067;&amp;#x306F;&amp;#x306A;&amp;#x3044;\n\n
  37. &amp;#x30FB;&amp;#x30D6;&amp;#x30E9;&amp;#x30F3;&amp;#x30C1;&amp;#x3092;&amp;#x5207;&amp;#x308A;&amp;#x66FF;&amp;#x3048;&amp;#x305F;&amp;#x5834;&amp;#x5408;&amp;#x3001;&amp;#x65E2;&amp;#x5B58;&amp;#x306E;&amp;#x30D6;&amp;#x30E9;&amp;#x30F3;&amp;#x30C1;&amp;#x306E;&amp;#x5185;&amp;#x5BB9;&amp;#x306F;&amp;#x65B0;&amp;#x3057;&amp;#x3044;&amp;#x5185;&amp;#x5BB9;&amp;#x306B;&amp;#x7F6E;&amp;#x304D;&amp;#x63DB;&amp;#x3048;&amp;#x3089;&amp;#x308C;&amp;#x308B;&amp;#x306E;&amp;#x3067;&amp;#x6CE8;&amp;#x610F;&amp;#x304C;&amp;#x5FC5;&amp;#x8981;\n&amp;#x30FB;Subversion&amp;#x306E;&amp;#x3088;&amp;#x3046;&amp;#x306B;&amp;#x300C;&amp;#x30D6;&amp;#x30E9;&amp;#x30F3;&amp;#x30C1;=&amp;#x30C7;&amp;#x30A3;&amp;#x30EC;&amp;#x30AF;&amp;#x30C8;&amp;#x30EA;&amp;#x300D;&amp;#x3068;&amp;#x3044;&amp;#x3046;&amp;#x6982;&amp;#x5FF5;&amp;#x3067;&amp;#x306F;&amp;#x306A;&amp;#x3044;\n\n
  38. &amp;#x30FB;&amp;#x30D6;&amp;#x30E9;&amp;#x30F3;&amp;#x30C1;&amp;#x3092;&amp;#x5207;&amp;#x308A;&amp;#x66FF;&amp;#x3048;&amp;#x305F;&amp;#x5834;&amp;#x5408;&amp;#x3001;&amp;#x65E2;&amp;#x5B58;&amp;#x306E;&amp;#x30D6;&amp;#x30E9;&amp;#x30F3;&amp;#x30C1;&amp;#x306E;&amp;#x5185;&amp;#x5BB9;&amp;#x306F;&amp;#x65B0;&amp;#x3057;&amp;#x3044;&amp;#x5185;&amp;#x5BB9;&amp;#x306B;&amp;#x7F6E;&amp;#x304D;&amp;#x63DB;&amp;#x3048;&amp;#x3089;&amp;#x308C;&amp;#x308B;&amp;#x306E;&amp;#x3067;&amp;#x6CE8;&amp;#x610F;&amp;#x304C;&amp;#x5FC5;&amp;#x8981;\n&amp;#x30FB;Subversion&amp;#x306E;&amp;#x3088;&amp;#x3046;&amp;#x306B;&amp;#x300C;&amp;#x30D6;&amp;#x30E9;&amp;#x30F3;&amp;#x30C1;=&amp;#x30C7;&amp;#x30A3;&amp;#x30EC;&amp;#x30AF;&amp;#x30C8;&amp;#x30EA;&amp;#x300D;&amp;#x3068;&amp;#x3044;&amp;#x3046;&amp;#x6982;&amp;#x5FF5;&amp;#x3067;&amp;#x306F;&amp;#x306A;&amp;#x3044;\n\n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. &amp;#x30FB;&amp;#x305F;&amp;#x3060;&amp;#x3057;&amp;#x4E00;&amp;#x5EA6;&amp;#x306F;clone&amp;#x3092;&amp;#x884C;&amp;#x3046;&amp;#x5FC5;&amp;#x8981;&amp;#x304C;&amp;#x3042;&amp;#x308B;\n
  45. \n
  46. \n
  47. &amp;#x30FB;&amp;#x3053;&amp;#x306E;&amp;#x30E1;&amp;#x30FC;&amp;#x30EB;&amp;#x306E;&amp;#x5834;&amp;#x5408;&amp;#x3001;VERSION&amp;#x30D5;&amp;#x30A1;&amp;#x30A4;&amp;#x30EB;&amp;#x304C;CHANGED&amp;#x3055;&amp;#x308C;&amp;#x3066;&amp;#x3044;&amp;#x308B;\n
  48. &amp;#x30FB;&amp;#x3053;&amp;#x306E;&amp;#x30E1;&amp;#x30FC;&amp;#x30EB;&amp;#x306E;&amp;#x5834;&amp;#x5408;&amp;#x3001;VERSION&amp;#x30D5;&amp;#x30A1;&amp;#x30A4;&amp;#x30EB;&amp;#x304C;CHANGED&amp;#x3055;&amp;#x308C;&amp;#x3066;&amp;#x3044;&amp;#x308B;\n
  49. &amp;#x30FB;&amp;#x3053;&amp;#x306E;&amp;#x30E1;&amp;#x30FC;&amp;#x30EB;&amp;#x306E;&amp;#x5834;&amp;#x5408;&amp;#x3001;VERSION&amp;#x30D5;&amp;#x30A1;&amp;#x30A4;&amp;#x30EB;&amp;#x304C;CHANGED&amp;#x3055;&amp;#x308C;&amp;#x3066;&amp;#x3044;&amp;#x308B;\n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. &amp;#x30FB;git fetch&amp;#x306F;&amp;#x73FE;&amp;#x5728;&amp;#x6709;&amp;#x52B9;&amp;#x306A;&amp;#x30D6;&amp;#x30E9;&amp;#x30F3;&amp;#x30C1;&amp;#x306B;&amp;#x306F;&amp;#x5F71;&amp;#x97FF;&amp;#x3092;&amp;#x4E0E;&amp;#x3048;&amp;#x306A;&amp;#x3044;\n
  57. \n
  58. \n
  59. \n
  60. \n
  61. &amp;#x30FB;&amp;#x904B;&amp;#x7528;&amp;#x65B9;&amp;#x91DD;&amp;#x306F;&amp;#x691C;&amp;#x8A0E;&amp;#x4E2D;&amp;#x3002;&amp;#x5F8C;&amp;#x65E5;&amp;#x9023;&amp;#x7D61;&amp;#x3059;&amp;#x308B;&amp;#x304C;&amp;#x3001;&amp;#x57FA;&amp;#x672C;&amp;#x3053;&amp;#x306E;&amp;#x30D5;&amp;#x30ED;&amp;#x30FC;&amp;#x306E;&amp;#x901A;&amp;#x308A;&amp;#x306B;&amp;#x9032;&amp;#x3081;&amp;#x308B;\n
  62. \n