SlideShare a Scribd company logo
2013/11/16
@matsukaz
入門
いつやるの?
1.1.0
修正履歴
・「データ領域を指定commitに戻す」のコマンドが
 このページだけ誤植 (P113)
・「ブランチの作成」のコマンドを修正 (P147)
・「Gitのブランチを作成して切り替える」のコマンドを
 修正 (P153、P154)
@matsukaz
松下 雅和
サイバーエージェント
エンジニア
DevLOVEスタッフ
今日のゴール
http://www.flickr.com/photos/flavijus/3635413767/
のコマンドと
裏の仕組みを理解
ただのコマンド
紹介じゃないよ!!
http://www.flickr.com/photos/aschultz/3407606139/
仕組みを知らずに
使っていると、
とんでもないこと
やらかしちゃう
かも?
つい先日は
Jenkinsの
開発者が...
https://groups.google.com/forum/#!msg/jenkinsci-dev/-myjRIPcVwU/
t4nkXONp8qgJ
Hi all,
I have triggered an involuntary "forced push" last night on the list of Jenkins-CI plugins indicated below in
this e-mail.
My apology
I did not realise that I actually had forced push permissions and I do apologise for the inconvenience
caused.
The operations pushed back the all the branches to around 1 month. The history is not lost and is still on the
GitHub server but on detached branches.
The solution
I can raise a request to GitHub to provide the "reflog" of those repositories and restore the branches to the
point before my forced push.
Alternatively the owners of those repositories can still perform a "forced push" to restore the correct position
of the branches.
(if you would like to do so, please write to the mailing list so that we do not overlap the recovery
operations)
AW - *PLEASE READ* Re: strange pushes on GitHub
lucamilanesio
antexec-plugin.git
artifactory-plugin.git
associated-files-plugin.git
audit2db-plugin.git
audit-trail-plugin.git
backend-pull-request-greeter.git
beaker-builder-plugin.git
branch-api-plugin.git
build-flow-plugin.git
buildgraph-view.git
build-pipeline-plugin.git
build-timeout-plugin.git
buildtriggerbadge-plugin.git
bytecode-compatibility-transformer.git
ci-game-plugin.git
clearcase-plugin.git
clearcase-ucm-plugin.git
cloudbees-folder-plugin.git
cloudbees-plugin-gateway.git
cloudtest-plugin.git
clover-plugin.git
cobertura-plugin.git
collabnet-plugin.git
collapsing-console-sections-plugin.git
compact-columns-plugin.git
compress-artifacts-plugin.git
conditional-buildstep-plugin.git
config-file-provider-plugin.git
configurationslicing-plugin.git
copyartifact-plugin.git
copy-project-link-plugin.git
copy-to-slave-plugin.git
cppcheck-plugin.git
credentials-plugin.git
crowd2-plugin.git
crowd-plugin.git
customtools-plugin.git
cvsclient.git
cvs-plugin.git
dashboard-view-plugin.git
datical-db-plugin.git
dependency-check-plugin.git
deploy-plugin.git
disable-failed-job-plugin.git
disk-usage-plugin.git
doclinks-plugin.gitugin.git
dry-plugin.git
dynamic-axis-plugin.git
ec2-plugin.git
elastic-axis-plugin.git
email-ext-plugin.git
envinject-lib.git
envinject-plugin.git
extended-choice-parameter-plugin.git
extra-columns-plugin.git
extras-executable-war.git
extreme-feedback-plugin.git
gearman-plugin.git
gerrit-trigger-plugin.git
gitbucket-plugin.git
git-chooser-alternative-plugin.git
git-client-plugin.git
git-plugin.git
global-build-stats-plugin.git
global-variable-string-parameter-plugin.git
gradle-jpi-plugin.git
grails-plugin.git
greenballs-plugin.git
groovy-postbuild-plugin.git
heavy-job-plugin.git
hockeyapp-plugin.git
http-request-plugin.git
humbug-plugin.git
instant-messaging-plugin.git
integrity-plugin.git
ironmq-notifier-plugin.git
ivytrigger-plugin.git
jacoco-plugin.git
jclouds-plugin.git
jira-plugin.git
jobConfigHistory-plugin.git
job-dsl-plugin.git
job-import-plugin.git
job-poll-action-plugin.git
jquery-plugin.git
jquery-ui-plugin.git
json-lib.git
kiuwan-plugin.git
label-verifier-plugin.git
ldap-plugin.git
leiningen-plugin.git
lib-annotation-indexer.git
lib-task-reactor.git
lib-windows-remote-command.git
literate-cli.git
logfilesizechecker-plugin.git
m2release-plugin.git
m2-repo-reaper-plugin.git
mailer-plugin.git
matrix-auth-plugin.git
maven-hpi-plugin.git
maven-info-plugin.git
mercurial-plugin.git
mesos-plugin.git
metadata-plugin.git
mock-security-realm-plugin.git
msbuild-plugin.git
naginator-plugin.git
nerrvana-plugin.git
nested-view-plugin.git
next-build-number-plugin.git
next-executions-plugin.git
parameterized-trigger-plugin.git
perforce-plugin.git
performance-plugin.git
persona-plugin.git
pitmutation-plugin.git
plain-credentials-plugin.git
plugin-compat-tester.git
postbuildscript-plugin.git
promoted-builds-plugin.git
prqa-plugin.git
publish-over-cifs-plugin.git
puppet-jenkins.git
radiatorview-plugin.git
rapiddeploy-plugin.git
release-plugin.git
repo-plugin.git
rich-text-publisher-plugin.git
robot-plugin.git
run-condition-plugin.git
rvm-plugin.git
scm2job-plugin.git
scm-api-plugin.git
scoring-load-balancer-plugin.git
script-scm-plugin.git
selenium-axis-plugin.git
selenium-builder-plugin.git
selenium-tests.git
skype-im-plugin.git
skytap-cloud-plugin.git
smartfrog-plugin.git
sms-plugin.git
sounds-plugin.git
ssh-agent-plugin.git
ssh-credentials-plugin.git
sshd-module.git
ssh-slaves-plugin.git
starteam-plugin.git
stashnotifier-plugin.git
subversion-plugin.git
suppress-stack-trace-plugin.git
swarm-plugin.git
synergy_scm-plugin.git
tap-plugin.git
teamconcert-plugin.git
testlink-plugin.git
tfs-plugin.git
thin-backup-plugin.git
throttle-concurrent-builds-plugin.git
tikal-multijob-plugin.git
timestamper-plugin.git
token-macro-plugin.git
transifex-plugin.git
translation-plugin.git
trilead-ssh2.git
unity3d-plugin.git
veracode-scanner-plugin.git
view-job-filters-plugin.git
virtualbox-plugin.git
vsphere-cloud-plugin.git
vstestrunner-plugin.git
walldisplay-plugin.git
warnings-plugin.git
weblogic-deployer-plugin.git
winstone.git
wix-plugin.git
ws-cleanup-plugin.git
xcode-plugin.git
xstream.git
xtrigger-lib.git
xunit-plugin.git
xvfb-plugin.git
xvnc-plugin.git
リビジョンが戻ったリポジトリたち
全部で184...(´;ω;`)ブワッ
不安を感じながら
使いたく
ないよね?
http://www.flickr.com/photos/tjflex/233579552/
仕組みが分かれば
どんなツールも
使いこなせる
http://www.flickr.com/photos/pennuja/5363515039/
仕組みから
しっかりと
理解しよう!!
※ といっても入門なので、深過ぎない程度で
http://www.flickr.com/photos/danielygo/7357503268/
Agenda
Gitの内部構造
ブ
ラ
ン
チ
リモートリポジトリ
Gitっておいしいの?
Gitの内部構造
ブ
ラ
ン
チ
リモートリポジトリ
Gitっておいしいの?
Agenda
Gitを
一言で言うと、
分散型
バージョン
管理システム
http://www.google.com/about/datacenters/gallery/#/tech/12
分散型じゃない
バージョン
管理システム
といえば・・・
http://cmpilato.blogspot.jp/2009/02/subversion-desktop-wallpaper.html
Subversion
の全体構成
ローカル
ディレクトリ
リポジトリ
ローカル
ディレクトリ
commit
ファイル
更新
update
(merge)
ローカル
ディレクトリ
リポジトリ
ローカル
ディレクトリ
commit
ファイル
更新
update
(merge)
ローカルは
ある時点の
変更履歴のみ
ローカル
ディレクトリ
リポジトリ
ローカル
ディレクトリ
commit
ファイル
更新
update
(merge)
リポジトリに
変更内容を反映
ローカル
ディレクトリ
リポジトリ
ローカル
ディレクトリ
commit
ファイル
更新
update
(merge)
リポジトリの
変更内容を取得
ローカル
ディレクトリ
リポジトリ
ローカル
ディレクトリ
commit
ファイル
更新
update
(merge)
Subversionで
一番気をつけるのは
commit
Subversion
の問題点
commit対象を
指定しづらい
(全て/個別)
commitの
取り消しは大変
いくつかの操作は
オンライン必須
・commit
・update
・log
リポジトリが
肥大化する
一方
Gitの場合は、
Gitの
全体構成
ローカル
ディレクトリ
リモート
リポジトリ
ローカル
ディレクトリ
ファイル
更新
ローカル
リポジトリ
ローカル
リポジトリ
commit
push
(merge/
rebase)
fetch
ローカル
ディレクトリ
リモート
リポジトリ
ローカル
ディレクトリ
ファイル
更新
ローカル
リポジトリ
ローカル
リポジトリ
commit
push
(merge/
rebase)
fetch
ローカルリポジトリは
リモートリポジトリの
完全な複製
ローカル
ディレクトリ
リモート
リポジトリ
ローカル
ディレクトリ
ファイル
更新
ローカル
リポジトリ
ローカル
リポジトリ
commit
push
(merge/
rebase)
fetch
ローカル
リポジトリに
変更内容を反映
ローカル
ディレクトリ
リモート
リポジトリ
ローカル
ディレクトリ
ファイル
更新
ローカル
リポジトリ
ローカル
リポジトリ
commit
push
(merge/
rebase)
fetch
リモート
リポジトリに
変更内容を反映
ローカル
ディレクトリ
リモート
リポジトリ
ローカル
ディレクトリ
ファイル
更新
ローカル
リポジトリ
ローカル
リポジトリ
commit
push
(merge/
rebase)
fetch
リモート
リポジトリから
変更内容を取得
ローカル
ディレクトリ
リモート
リポジトリ
ローカル
ディレクトリ
ファイル
更新
ローカル
リポジトリ
ローカル
リポジトリ
commit
push
(merge/
rebase)
fetch
リモート
リポジトリの
変更内容を反映
ローカル
ディレクトリ
リモート
リポジトリ
ローカル
ディレクトリ
ファイル
更新
ローカル
リポジトリ
ローカル
リポジトリ
commit
push
(merge/
rebase)
fetch
fetch
+
merge/rebase
pull
ローカル
ディレクトリ
リモート
リポジトリ
ローカル
ディレクトリ
ファイル
更新
ローカル
リポジトリ
ローカル
リポジトリ
commit
push
(merge/
rebase)
fetch
Gitで一番
気をつけるのは
merge/rebase
Gitのメリット
commit対象の
管理が簡単
コミット内容を
後から修正可能
ほとんどの操作が
ローカルで完結
(push/fetch以外)
ブランチや
タグ操作が高速
効率的に
リポジトリ内の
データを保持
要は、従来の
バージョン管理
システムよりも
いつやるの?Git入門 v1.1.0
管理対象に
合わせて様々な
ワークフローで
利用されている
※ 書籍「Pro Git」より
代表的な例
中央集権型
Subversionに近い運用
共有リポジトリ
と常に同期
共有
リポジトリ
developer developer developer
統合
マネージャー型
pull request
メイン
リポジトリ
developer
public
developer
public
developer
private
developer
private
integration
manager
変更を公開
&反映依頼変更を
反映
変更
変更を
マージ
独裁者と
若頭型
Linuxなど巨大プロジェクト
メイン
リポジトリ
developer
public
developer
public
developer
public
若頭
独裁者
若頭分を
マージ
developer
分をマージ
変更を
反映
変更
Gitの可能性は∞!!
http://www.flickr.com/photos/llamnuds/2723112918/
ブランチ・タグの
運用ルールも
いろいろ
GitHub Flow
git-flow
https://github.com/darashi/horesa.se
Agenda
Gitの内部構造
ブ
ラ
ン
チ
リモートリポジトリ
Gitっておいしいの?
Gitで大事なのは
3つのデータ領域
作業ディレクトリ
(ワークツリー)
Gitディレクトリ
ステージング・エリア
(インデックス)
この3つを
理解出来れば
Gitは怖くない!!
http://www.flickr.com/photos/myke/2998073342/
もう一度
Gitの全体図
ローカル
ディレクトリ
リモート
リポジトリ
ローカル
ディレクトリ
ファイル
更新
ローカル
リポジトリ
ローカル
リポジトリ
commit
push
(merge/
rebase)
fetch
ローカル
ディレクトリ
ローカル
ディレクトリ
リモート
リポジトリ
ファイル
更新
ローカル
リポジトリ
ローカル
リポジトリ
commit
push
fetch
(merge/
rebase)
ローカル環境
ローカル環境
ローカル環境の
内部構造
物理構造
git-root
parent
child.txt
hello.txt
論理構造
.git
※ 物理構造は参考程度で
物理構造
git-root
parent
child.txt
hello.txt
論理構造
.git
Gitディレクトリ
作業ディレクトリ
(ワークツリー)
※ 物理構造は参考程度で
物理構造
git-root
parent
child.txt
hello.txt
論理構造
.git
Gitが管理して
いるディレクトリ Gitディレクトリ
作業ディレクトリ
(ワークツリー)
実際に作業中の
ディレクトリ
※ 物理構造は参考程度で
物理構造
git-root
parent
child.txt
hello.txt
…
.git
objects
config
論理構造
Gitディレクトリ
作業ディレクトリ
(ワークツリー)
index
※ 物理構造は参考程度で
物理構造
git-root
parent
child.txt
hello.txt
…
.git
objects
index
config
論理構造
Gitディレクトリ
作業ディレクトリ
(ワークツリー)
ステージング・エリア
(インデックス)
※ 物理構造は参考程度で
※ 物理構造は参考程度で
物理構造
git-root
parent
child.txt
hello.txt
…
.git
objects
index
config
論理構造
Gitディレクトリ
作業ディレクトリ
(ワークツリー)
ステージング・エリア
(インデックス)
3つの
データ領域で
構成されている
Gitコマンド =
データ領域間の
ファイルの操作
Gitコマンドを
実行してみよう!
http://www.flickr.com/photos/pdstahl/3469156022/
作業
ディレクトリ
初期状態のローカル環境
作業
ディレクトリ
初期状態のローカル環境
file2
file1 dir1
file3
新しい
ファイルを
作成
Git管理を
開始する
git init
作業
ディレクトリ
file2
file1 dir1
file3
git init
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
git init
領域準備 領域準備
file2
file1 dir1
file3
リポジトリに
追加したい対象を
指定する
git add <filepattern>...
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
file1 dir1
file3
git add file1 dir1/file2
file2
file1
file2
file1 dir1
file3
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
git add file1 dir1/file2
ステージ
される
ステージ
される
dir1
ディレクトリは
独自の
ツリー構造
更新内容を
リポジトリに
登録する
git commit -m <msg>
file2
file1
file2
file1 dir1
file3
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
git commit -m 'コミットするよ。'
dir1
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
git commit -m 'コミットするよ。'
file2
1a401e
file1
file2
file1
file2
file1 dir1
file3
更新内容
を登録
コミットID
を発行
dir1 dir1
ファイルを
修正した場合も
git add
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
1a401e
file1
file2
file1
file2
file1’ dir1
file3
ファイル
を修正
dir1 dir1
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
1a401e
file1
file2
file1
file2
dir1
file3
git add .
dir1 dir1
file1’
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
1a401e
file1
file2file2
dir1
file3
git add .
file3
「.」は全ての
未登録ファイルが
ステージされる
dir1 dir1
file1’ file1’
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
1a401e
file1
file2file2
dir1
file3 file3
git commit -m 'もっとコミット。'
dir1 dir1
file1’ file1’
file1’
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
1a401e
file1
510db8
file3file2 file3file2
dir1
file3
git commit -m 'もっとコミット。'
dir1 dir1
更新内容
を登録
file1’ file1’
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
1a401e
file1
510db8
file3file2 file3file2
dir1
file3
git commit -m 'もっとコミット。'
前のcommitが
親となる
dir1 dir1
file1’file1’ file1’
ファイルを
削除する
git rm <file>...
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
1a401e
file1
510db8
file3
file1’
file2
file1’
file3file2
file1’ dir1
file3
git rm dir1/file2
dir1 dir1
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
1a401e
file1
510db8
file3
file1’file1’
file3
file1’ dir1
file3
git rm dir1/file2
dir1 dir1
ファイルが
削除される
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
1a401e
file1
510db8
file3
file1’file1’
file3
file1’ dir1
file3
git commit -m '削除情報をコミット。'
dir1 dir1
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
1a401e
file1
510db8 6ccfda
file3
file1’file1’
file3
file1’ dir1
file3
git commit -m '削除情報をコミット。'
更新内容
を登録
dir1 dir1
ステージングエリア
をGitリポジトリの
HEAD状態に戻す
git reset HEAD <file>
※ HEAD=Gitリポジトリが見ている最新のcommit位置
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
1a401e
file1
510db8 6ccfda
file3
file1’file1’
file3’
file1’ dir1
file3’
dir1 dir1
ステージ
されてる
git addした直後
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
1a401e
file1
510db8 6ccfda
file3
file1’file1’file1’ dir1
git reset HEAD dir1/file3
dir1 dir1
file3’file3’
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
1a401e
file1
510db8 6ccfda
file3
file1’file1’
file3
file1’ dir1
git reset HEAD dir1/file3
dir1 dir1
ステージする前の
状態に戻される
file3’
作業ディレクトリを
ステージングエリア
の状態に戻す
git checkout -- <file>
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
1a401e
file1
510db8 6ccfda
file3
file1’file1’
file3
file1’ dir1
ファイル
を修正
dir1 dir1
ファイルを変更した直後
file3’
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
1a401e
file1
510db8 6ccfda
file3
file1’file1’
file3
file1’ dir1
git checkout -- dir1/file3
dir1 dir1
file3’
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
1a401e
file1
510db8 6ccfda
file3
file1’file1’
file3
file1’ dir1
file3
git checkout -- dir1/file3
修正する前の
状態に戻る
dir1 dir1
ここまでの流れを
整理すると
Gitディレクトリ
作業
ディレクトリ
ステージング
エリア
git reset HEAD <file>
git add/rm/mv
git checkout -- <file>
git commit
git init
ファイル更新
その他の
基本コマンド
ファイルや
ディレクトリを
移動する
git mv
データ領域を
指定commitの
状態に戻す
git reset --<mode> <commit>
git resetのオプションなどは以下の説明が分かりやすいので詳細はそちらで
http://d.hatena.ne.jp/murank/20110327/1301224770
(soft / hard / mixed)
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
1a401e
file1
510db8 6ccfda
file3
file1’file1’
file3
file1’ dir1
file3
git reset --hard HEAD^
dir1 dir1
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
1a401e
file1
510db8 6ccfda
file3
file1’file1’
file3
file1’ dir1
file3
git reset --hard HEAD^
file2file2
HEADの一つ
前のcommitの
状態に戻る
dir1 dir1
作業ディレクトリ
の状態を見る
git status
コミットログを
見る
git log --graph --color
--graphオプションをつけるとコミットの流れをグラフ表示してくれる
Gitリポジトリを
閲覧するための
GUI起動
gitk
いつやるの?Git入門 v1.1.0
Agenda
Gitの内部構造
ブ
ラ
ン
チ
リモートリポジトリ
Gitっておいしいの?
ブランチとは
メインとは
別の流れで
作業を続ける機能
Subversionの場合
/trunk
/1.0
1.0.0
/1.1
1.0.1
1.0.2
trunkへ
マージ
END
trunk 1.0.0/1.0/trunk branch tag
Gitには
trunkがなく、
全てがブランチ
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
1a401e
file1
510db8 6ccfda
file3
file1’file1’
file3
file1’ dir1
file3
dir1 dir1
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
file2
1a401e
file1
510db8 6ccfda
file3
file1’file1’
file3
file1’ dir1
file3
dir1 dir1
master
Git管理を開始すると
masterブランチが
デフォルトで用意される
ブランチの
一覧を表示する
git branch -a
-aオプションをつけると、後述するリモートブランチも一覧で表示される
コミットグラフで
表現すると
A B
master
A B
master
ブランチは
commitの位置を
指すだけ
commitすると
masterの位置も
移動するmaster
A B C
developブランチを
切った場合も、
同じcommitを指す
master
A B C
develop
developブランチの切り方は後述
master
A B C D
masterでcommit
するとmasterだけ
移動する
develop
master
A B C D
E
develop
developも
masterとは別で
移動する
master
A B C D
E
developの変更を
masterにmergeする場合
develop
master
A B C D
E
masterで
developを
merge
develop
developの変更を
masterにmergeする場合
master
A B C D
E
F
DとEの両方の
commitが
親となる
conflict
する場合は
対応
develop
developの変更を
masterにmergeする場合
develop
master
A B C D
E
F G
H
developの変更を
masterにmergeする場合
その後も
commitできる
master
A B C D
E
develop
でmasterを
rebase develop
masterの変更を
developにrebaseする場合
master
A B C D
E
developと
masterの共通先祖に
移動、そこからEの
diffを取得
develop
masterの変更を
developにrebaseする場合
master
A B C D
E’E
取得した
diffをmasterに
適用して新たな
commitを作成
develop
masterの変更を
developにrebaseする場合
master
A B C D
E’ conflict
する場合は
対応develop
masterの変更を
developにrebaseする場合
A B C D
E’
master
F
G
develop
masterの変更を
developにrebaseする場合
その後も
commitできる
merge
or
rebase ?
いろいろ論争が
あるので
適材適所で
http://www.flickr.com/photos/bastiaanssen/4628611135/
ブランチを
操作してみよう!
http://www.flickr.com/photos/statkraft/4077416680/
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
A
file1
master
HEAD
B
file1’file1’file1’
少しcommitしたローカル環境
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
A
file1
master
HEAD
B
file1’file1’file1’
少しcommitしたローカル環境
現在作業中の
ブランチを
表す
ステージングエリアは
HEADとの差分で
更新を判断
Gitのブランチを
作成する
git branch
<new_branch> [<start_point>]
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
git branch develop
A
file1
master
HEAD
B
file1’file1’file1’
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
git branch develop
A
file1
master
HEAD
B
develop
file1’file1’file1’
develop
ブランチが
出来るHEAD
の位置は
変わらない
作業中の
ブランチを
切り替える
git checkout <branch>
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
git checkout develop
A
file1
master
HEAD
B
file2
file1’
C
file1’file1’
develop
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
git checkout develop
A
file1
master
HEAD
B
develop
file2
file1’
C
HEADの位置
が変わる
file2file2
HEADに
合わせて復元
file1 file1
git checkout -b
<new_branch> [<start_point>]
Gitのブランチを
作成して
切り替える
git checkout -b
<new_branch> [<start_point>]
git checkout <new_branch>
git branch
<new_branch> [<start_point>]
+
=
git merge <branch>
現在のブランチに
指定ブランチを
マージする
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
git merge develop
file1’file1’
A
file1
master
HEAD
B
develop
file2
file1’
C
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
git merge develop
file2
file1’
file2
file1’
merge
commitが
作られる
A
file1
master
HEAD
B
develop
file2
file1’
D
C
Cの変更も
反映される
git rebase <branch>
現在のブランチを
指定ブランチから
リベースする
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
A
git rebase master
file1
file2file2
file1file1
master HEAD
B develop
C
file2
file1’
作業
ディレクトリ
ステージング
エリア
Gitディレクトリ
A
master HEAD
git rebase master
B develop
C’
file2
file1
file1’
file2file2
file1’file1’
masterの
最新commitに
rebaseされる
Bの変更も
反映される
Agenda
Gitの内部構造
ブ
ラ
ン
チ
リモートリポジトリ
Gitっておいしいの?
リモート
リポジトリは
ブランチで連携
コミットグラフで
表現すると
ローカルリポジトリリモートリポジトリ
master
A B
ローカルリポジトリリモートリポジトリ
master
A B
origin/master
master
A B
cloneで
リモートリポジトリが
ローカルにコピー
される
ローカルリポジトリリモートリポジトリ
master
A B
origin/master
master
A B
リモートブランチ
(リモートを追跡する)
同名の
ローカルブランチも
出来る
ローカルリポジトリリモートリポジトリ
master
A B
origin/master
master
A B
リモートリポジトリ
/ブランチ名
ローカルリポジトリリモートリポジトリ
master
A B
origin/master
master
C
A B
リモート
が先に進んだ
場合は
ローカルリポジトリリモートリポジトリ
master
A B
origin/master
master
C
A B C
fetchすると
リモートブランチ
も同じ状態に
ローカルリポジトリリモートリポジトリ
master
A B
origin/master
master
C
A B C
ローカルブランチ
はリモートブランチと
merge/rebase
ローカルリポジトリリモートリポジトリ
master
A B
origin/master
master
C
A B
pull=
fetch+merge/rebase
なので
ローカルリポジトリリモートリポジトリ
master
A B
origin/master
master
C
A B C
pullなら
ローカルブランチも
リモートブランチも
同時に更新
ローカルリポジトリリモートリポジトリ
master
A B
origin/master
master
C
A B C D
commit
した場合は
ローカルリポジトリリモートリポジトリ
master
A B
origin/master
master
C D
A B C D
push!!
リモートブランチと
リモートリポジトリに
反映
ローカルリポジトリリモートリポジトリ
master
A B
origin/master
master
C D F
A B C D E
両方
更新された
場合は
ローカルリポジトリリモートリポジトリ
master
A B
origin/master
master
C D F
A B C D E G
F
一度
mergeして
ローカルリポジトリリモートリポジトリ
master
A B
origin/master
master
C D F
push!!
G
A B C D E G
F
E
ローカルリポジトリリモートリポジトリ
master
A B
origin/master
master
C D F
A B C D E
他の方法
としては
ローカルリポジトリリモートリポジトリ
master
A B
origin/master
master
C D F
A B C D F
E
rebase
もアリ
E’
ローカルリポジトリリモートリポジトリ
master
A B
origin/master
master
C D F
push!!
E’
A B C D F E’
ローカルリポジトリリモートリポジトリ
master
A B C E F
D G H
develop
master
A B C E F I
D G
develop
origin/master
origin/develop
だんだん複雑
になる...
リモート
リポジトリを
操作してみよう!
http://www.flickr.com/photos/loozrboy/7311781992/
リモートリポジトリ
をローカルに複製
git clone <url>
リモートリポジトリ A B
master
git clone git@github.com:a/b.git
作業
ディレクトリ
ステージング
エリア
ローカルリポジトリ
リモートリポジトリ
file1’file1’
A B
master
file1 file1’
master
A B
HEAD
origin/master
データ領域が
作られる
git clone git@github.com:a/b.git
ファイルも
復元される
リモートリポジト
リに変更を送信
git push <remote> <refspec>
作業
ディレクトリ
ステージング
エリア
ローカルリポジトリ
リモートリポジトリ
file1’file1’
A B
master
file1’
master
A B
HEAD
origin/master
file1
作業
ディレクトリ
ステージング
エリア
ローカルリポジトリ
リモートリポジトリ
file1’file1’
A B
master
file2
file1’
master
A B
HEAD
origin/masterファイル
作成
file1
作業
ディレクトリ
ステージング
エリア
ローカルリポジトリ
リモートリポジトリ
file1’file1’
A B
master
file2 file2
file1’
master
A B
HEAD
origin/master
git
add
git add file2
file1
作業
ディレクトリ
ステージング
エリア
ローカルリポジトリ
リモートリポジトリ
file1’file1’
A B
master
file2 file2
file1’
master
A B
HEAD
origin/master
C
file2
git
commit
git commit -m 'add file2'
file1
作業
ディレクトリ
ステージング
エリア
ローカルリポジトリ
リモートリポジトリ
file1’file1’
A B C
master
master
A B
HEAD
origin/master
C
リモートリ
ポジトリ反映
file2 file2
git push origin master
file1’ file2file1
リモートブランチ
を最新に更新
git fetch <remote> <refspec>
作業
ディレクトリ
ステージング
エリア
ローカルリポジトリ
リモートリポジトリ
file1’file1’
A B C
git fetch origin master
master
master
A B
HEAD
origin/master
file1’file1
作業
ディレクトリ
ステージング
エリア
ローカルリポジトリ
リモートリポジトリ
file1’file1’
A B C
git fetch origin master
master
master
A B
HEAD
origin/master
C
リモート
ブランチ更新
file1’ file2file1
git pull <remote> <refspec>
git merge <branch>
git fetch <remote> <refspec>
=
+
作業
ディレクトリ
ステージング
エリア
ローカルリポジトリ
リモートリポジトリ
file2file2
A B C
git pull origin master
master
masterA B
HEAD
origin/master
D
file2file1’file1
作業
ディレクトリ
ステージング
エリア
ローカルリポジトリ
リモートリポジトリ
master
A B
HEAD
origin/master
C
D
E
A B C
master
git pull origin master
file2
file3
file3file3
file2file2
リモート
ブランチ更新
merge
file1’file1
git pull <remote> <refspec> --rebase
git rebase <branch>
git fetch <remote> <refspec>
+
作業
ディレクトリ
ステージング
エリア
ローカルリポジトリ
リモートリポジトリ
file2file2
A B C
git pull origin master --rebase
master
masterA B
HEAD
origin/master
D
file2file1’file1
作業
ディレクトリ
ステージング
エリア
ローカルリポジトリ
リモートリポジトリ
file2file2
A B C
git pull origin master --rebase
master
file1
file1’
masterA B
HEAD
origin/master
D’
file2
C
file3
file3file3
rebase
リモート
ブランチ更新
まとめ
細かいコマンドは
まだまだあるので
ググってね
まずは
ローカルでの
操作に慣れよう!!
リモートとの
やりとりは
pushとpullを使う
fetchや個別の
merge/rebaseは
慣れてから
普段から
リモートとの
ズレを抑える
ように心がける
おかしくなったら
データ領域の
状態を冷静に見る
大事なのは
データ領域!!
これで
Gitも
余裕だね!!
参考URL
- Git初心者が見るべきサイトまとめ
- http://matome.naver.jp/odai/2136491451473222801
- いろいろオススメサイトをまとめました!
ご清聴
ありがとう
ございました
こういう資料に対する投げ銭的なものを試してみたいと思ってたので、
もしよろしければ・・・!15円からできるソーシャルカンパサービスだそうです。
http://kampa.me/t/dev

More Related Content

いつやるの?Git入門 v1.1.0

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy