Priner of git

55

description

The purpose of this is the following: 1. Remember the basic git commands. 2. To understand the behavior of git. 3. One person will be able to git.

Transcript of Priner of git

Page 1: Priner of git
Page 2: Priner of git

自己紹介

Page 3: Priner of git

Name:

佐川 夫美雄@albatrosary

http://ameblo.jp/sgw3a/

Users Group:Tokyo.R/html5j.org/jsug/mybatis-users/(ソフトウェア品質技術者のための)データ分析会

Page 4: Priner of git

今日はハンズオンですので実際にコマンド叩きます途中ミスってもそれはそれで、デモですので空気を呼んで心広い対応をお願いします

Page 5: Priner of git

では、はじめます

Page 6: Priner of git

初級編の目標

・よく使う git コマンドを覚える

・git の基本動作を身につける

・1人 git でがんばれる(複数人 git はまた今度)

Page 7: Priner of git

git の特徴

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

・多くのオープンソースプロジェクトで使われている ← オープンソースを利用するときに git の知識を持っている方がよりよい

・1人バージョン管理、チームでのバージョン管理など気軽にファイル管理できる

Page 8: Priner of git

git のイメージ

Repository

Repository

Repository

IndexWorking Tree

Repository

ローカルOrigin

push/pull

commit/checkoutadd/reset

Page 9: Priner of git

自分の Repositoryを壊しても誰からも怒られない

Page 10: Priner of git

それぞれのファイルの差分を個別に管理

スナップショットとしてデータを管理

git と svn の違い

Page 11: Priner of git

ちなみに

Page 12: Priner of git

gitgithubgithub:E(github Enterprise)

これ違うものです

Page 13: Priner of git

git は 分散型バージョン管理システムgithub は git を使うためのハブgithub:E(github Enterprise) は github の イメージ(VMを含め)をローカル環境に置けるもの

Page 15: Priner of git
Page 16: Priner of git

ようやく本題!!

Page 17: Priner of git

git のインストールMAC だと既に入ってます。MacPortsからダウンロードWindows では下記 url からダウンロードします。msys版とcygwin版がありますが、msys版がおすすめ

http://code.google.com/p/msysgit/downloads/list

Page 18: Priner of git

git の状態Working Tree:git 配下でユーザが作業する場所Index:リポジトリー登録する前の一時領域git はスナップショット(ファイルの固まり)として管理しているため Index というバケツを用意しているRepository:管理するファイルを蓄積するデータベース。CVS、Subversionでは全体として1つの管理だが、git ではローカルにもリポジトリーが存在する。

この概念を頭に入れてファイル管理するのでかなり面倒覚えると超ハッピー!!

Page 19: Priner of git

git の状態遷移git init

git add git commit

git checkout

git diff git diff --cached

git diff HEAD

Sample.txtSample.txt Sample.txt

demo.txtdemo.txtdemo.txt

Sample.txtSample.txt

demo.txtdemo.txt

Index RepositoryWorking Tree

git reset

git checkout

Page 20: Priner of git

よく使うコマンドgit config:git の設定をするgit init:git の管理下にディレクトリを設定するgit add:インデックスへのファイル登録git commit:リポジトリへファイルを登録するgit rm:git からファイルを削除する。Working Treeから実態を削除git show:コミット情報を表示するgit status:リポジトリの状態を確認するgit checkout:変更前に移動したりもとに戻ったりするgit reset:変更をなかったことにするgit revert:コミットをなかったことにする(commit を作る)git diff:各ステージの差分を確認するgit log:コミットログの確認をする

.gitignoreファイル:リポジトリの管理対象外にする定義ファイル

.gitconfigファイル:git configコマンドで発行された設定情報を保持する

Page 21: Priner of git

ハンズオン

Page 22: Priner of git

$ mikdir temp$ cd temp

git 用の作業ディレクトリ作成

Page 23: Priner of git

$ git init

git 用に初期化

.gitディレクトリが作成されます

Page 24: Priner of git

.git の中身を確認

Page 25: Priner of git

$ git config --global user.name “Fumio SAGAWA”$ git config --global user.email [email protected]

git の設定

Page 26: Priner of git

git config --global:ユーザ(ログインユーザ)の git 設定git config --system:システム全体の git 設定git config:リポジトリの git 設定

git config

Page 27: Priner of git

ここまでが git を使う準備ですsample.txt というファイルを使って実際にコマンドを叩いて行きます

Page 28: Priner of git

$ echo hogehogehoge > sample.txt

git に管理させるファイルを生成

Page 29: Priner of git

$ git add sample.txt

git add の発行

git addでこれが生成されている

Page 30: Priner of git

$ git diff$ git diff --cached$ git diff HEAD

Working Tree, Index, Repositoryの違いを確認

Page 31: Priner of git

HEAD:最新のコミットHEAD~:HEADの一つ前HEAD~~:HEADの二つ前HEAD~2:HEAD~~と同じHEAD^: HEAD~と同じHEAD^^: HEAD~~と同じ

HEAD について

Page 32: Priner of git

$ vi sample.txt

ファイルの中身を変更しWorking Tree, Index, Repositoryの違いを確認

Page 33: Priner of git

$ git add sample.txt$ git commit -m “first commit”

変更をすべて適用し commit

git commitでこれが生成されている

Page 34: Priner of git

Working Tree, Index, Repositoryの違いを確認

Page 35: Priner of git

$ git add sample.txtsample.txt を編集し git add

Page 36: Priner of git

Working Tree, Index, Repositoryの違いを確認

Page 37: Priner of git

更に sample.txt を編集しWorking Tree, Index, Repositoryの違いを確認

Page 38: Priner of git

$ git status

git status は?

Page 39: Priner of git

$ git log

git log は?

Page 40: Priner of git

$ git show

git show は?

Page 41: Priner of git

Woring Treeで定義された内容をgit commit し

git status, git log, git showを確認する

Page 42: Priner of git

再度commit します

コマンドの打ち間違え

Page 43: Priner of git

$ git status

git status は?

Page 44: Priner of git

$ git log

git log は?

Page 45: Priner of git

$ git show

git show は?

Page 46: Priner of git

$ git rm sample.txt

git からファイルを削除する

Page 47: Priner of git

この状態でgit status, git log, git show, git diff

を確認する

Page 48: Priner of git

$ git status

git status は?

Page 49: Priner of git

$ git log

git log は?

Page 50: Priner of git

$ git show

git show は?

Page 51: Priner of git

$ git diff$ git diff --cached$ git diff HEAD

git diff は?

Page 52: Priner of git

$ git checkout HEAD sample.txt

git から check out してみる

Page 53: Priner of git

次回(来週)は、複数人で利用するための方法をやります

・merge・branch・push / pull・tag・clone

・svn 連携

Page 54: Priner of git

参考書

Page 55: Priner of git

ご清聴ありがとうございました