Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Git ハンズオン Part 1 / Git Handson Part 1
Search
takasp
September 25, 2018
0
55
Git ハンズオン Part 1 / Git Handson Part 1
takasp
September 25, 2018
Tweet
Share
More Decks by takasp
See All by takasp
監視のための統計入門 / Introduction to Statistics for Monitoring
takasp
0
100
Google App Engineを始めよう / Getting Started with Google App Engine
takasp
0
47
Git中級者になるためのrebase入門 / Introduction to rebase to become an intermediate Git user
takasp
0
52
GitHubで始めるdotfiles管理 / Getting started with GitHub for dotfiles management
takasp
0
33
第三回 Datadog 共有会 / Datadog Sharing 3rd
takasp
0
70
第二回 Datadog 共有会 / Datadog Sharing 2nd
takasp
0
72
Datadog 共有会 / Datadog Sharing
takasp
1
49
Docker ハンズオン 基礎編2 / Docker Handson Basic 2
takasp
1
88
Docker ハンズオン 基礎編1 / Docker Handson Basic 1
takasp
1
170
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
StorybookのUI Testing Handbookを読んだ
zakiyama
26
5.2k
Designing for humans not robots
tammielis
249
25k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Building Your Own Lightsaber
phodgson
102
6.1k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
The World Runs on Bad Software
bkeepers
PRO
65
11k
A designer walks into a library…
pauljervisheath
202
24k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Designing the Hi-DPI Web
ddemaree
280
34k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Transcript
Git ϋϯζΦϯ Part 1 # גࣜձࣾΤΞʔΫϩʔθοτ ࣾษڧձ Vol.3 @takasp 20189݄25
͜ͷࢿྉɺ ɾGit ͕ΠϯετʔϧࡁΈͰ͋Δ͜ͱ ɾGitHub ͷΞΧϯτΛ͍࣋ͬͯΔ͜ͱ Λલఏͱ͍ͯ͠·͢ɻ
͢͜ͱ • Git ͷ֓ཁ • Git ͷίϚϯυ • Git ͷίϚϯυΛͬͨϋϯζΦϯ
ຊѻ͏ Git ίϚϯυ • git add • git commit •
git push • git branch • git status • git merge • git init • git log • git clone • git pull • git diff • git config • git checkout
Git ͷ֓ཁ
Git ͱ • มߋཤྺΛهɾ͢ΔͨΊͷ ࢄܕόʔδϣϯཧγεςϜʢVCSʣ • Linux Χʔωϧͷιʔείʔυཧʹ ༻͍ΔͨΊʹϦʔφεɾτʔόϧζʹΑͬͯ ։ൃ͞Εͨ
ϑΝΠϧΛཧ͢Δ • ԿΛཧ͍ͨ͠ͷ͔ʁ • ୭͕ʁ • ͍ͭʁ • ͲͷϑΝΠϧΛʁ •
ԿΛมߋͨ͠ʁ JOEFY@࠷ऴ൛IUNM JOEFY@࠷ऴ൛IUNM JOEFY@OFXIUNM JOEFY@OFXIUNM JOEFY@IUNM JOEFY@IUNM JOEFY@IUNM JOEFYIUNM
Git ΛͬͨྲྀΕ 1 )5.-ϑΝΠϧ ΛՃ commit1 HEAD దͳίϛοτ ϝοηʔδΛ͚ͭΔ HEAD:
ݱࡏΛࢦࣔ͢͠࡞ۀঢ়ଶ commit: มߋͷཤྺΛهͨ͠ͷ
Git ΛͬͨྲྀΕ 1 2 )5.-ϑΝΠϧ ΛՃ JNHλάΛՃ commit1 commit2 HEAD
ίϛοτΛՃͨ͠ ίϛοτΛՃ͢Δͱ HEAD͕ਐΉ
Git ΛͬͨྲྀΕ 1 2 3 )5.-ϑΝΠϧ ΛՃ JNHλάΛՃ UJUMFΛมߋ commit1
commit2 commit3 HEAD ίϛοτΛՃͨ͠ ߋʹHEAD͕ਐΉ
Git ΛͬͨྲྀΕ 1 2 3 4 )5.-ϑΝΠϧ ΛՃ JNHλάΛՃ UJUMFΛมߋ
DTTΛमਖ਼ HEAD commit1 commit2 commit3 commit4 ίϛοτΛաڈʹ ḪΔ͜ͱͰ͖Δ
ϒϥϯν 1 2 3 4 merge merge: ϒϥϯνಉ࢜Λ ݁߹͢Δػೳ 2
5 feature ϒϥϯν fix ϒϥϯν ϝΠϯͷϒϥϯν branch: ཤྺΛࢬ͔Εͤͯ͞ ه͢Δػೳ
ࢄܕͱूதܕ தԝϦϙδτϦ ϦϞʔτϦϙδτϦ ूதܕ ࢄܕ ొ ొ औಘ औಘ ొ
औಘ ίϛοτ ొ औಘ ίϛοτ ϩʔΧϧ ϦϙδτϦ ϩʔΧϧ ϦϙδτϦ
ϦϙδτϦ ϦϞʔτϦϙδτϦ ϩʔΧϧϦϙδτϦ ϩʔΧϧϦϙδτϦ ϩʔΧϧϦϙδτϦ ϦϞʔτϦϙδτϦʹ ࡞ۀऀ͕ΞΫηεͯ͠ɺ ϩʔΧϧϦϙδτϦΛ ௨ͯ͠ΓͱΓ͢Δ ϦϙδτϦ:
όʔδϣϯཧΛ ߦ͏ॴ
ओཁͳ Git ϗεςΟϯάαʔϏε
ίϚϯυϥΠϯͰ֮͑Α͏ • ࠷ऴతʹ GUI Λͬͯྑ͍͕ɺ ෦ͰΘΕΔίϚϯυͷҙຯ͕͔ͬͯ Θͳ͍ͱɺԿΛ͢Δͷ͔͔Γʹ͍͘ • ෦ͰΘΕΔίϚϯυͱ GUI
ͷ໊শ͕ ҟͳΔ͜ͱ͕͋Δ • ωοτͰௐΔͱίϚϯυ͕ग़ͯ͘Δ
࠷ݶ͓͖͍֮͑ͯͨ Linux ίϚϯυ • pwd (print working directory) : ݱࡏͷσΟϨΫτϦΛදࣔ͢Δ
• cd (change directory) : ଞͷσΟϨΫτϦʹҠಈ͢Δ • ls (list) : ݱࡏͷσΟϨΫτϦͷσΟϨΫτϦϑΝΠϧΛදࣔ͢Δ • mkdir (make directory) : σΟϨΫτϦΛ࡞͢Δ • mv (move) : ϑΝΠϧΛҠಈ͢Δ • cp (copy) : ϑΝΠϧΛίϐʔ͢Δ • rm (remove) : ϑΝΠϧσΟϨΫτϦΛআ͢Δ
ࣄલ४උ
git config Ͱઃఆ͠Α͏ • ϢʔβʔใΛઃఆ͢Δ • editor ͷઃఆʢVisual Studio Code
Ͱىಈ͢Δྫʣ • ઃఆΛ֬ೝ͢Δ git config --global user.name takasp git config --global user.email
[email protected]
git config --global core.editor "code --wait" git config --global --list
ϩʔΧϧϦϙδτϦΛ࡞͢Δ • λʔϛφϧ͔ΒҙͷσΟϨΫτϦΛ࡞͠ ͯҠಈ͢Δ • ϩʔΧϧϦϙδτϦΛ࡞͢Δ mkdir git-handson01 cd
git-handson01 git init
ίϛοτ͢ΔྲྀΕΛ֮͑Α͏
ίϛοτ͢ΔྲྀΕ ϩʔΧϧϦϙδτϦ ϩʔΧϧϦϙδτϦʹ ίϛοτ͢Δ εςʔδʹҠಈ͢Δ ϑΝΠϧΛมߋ͢Δ
ϑΝΠϧΛ࡞͢Δ • ҎԼͷςΩετΛؚΉ README.md ϑΝΠϧ Λ࡞͢Δ # Git ॳΊͯͷ Git
ϑΝΠϧͰ͢ɻ ֯εϖʔε 2 ݸΛ ޙΖʹೖΕ͓ͯ͘ͱվߦʹͳΔ (markdown ه๏)
ঢ়ଶΛ֬ೝ͢Δ • git status ίϚϯυͰݱࡏͷঢ়ଶΛ֬ೝ͢Δ • ͢ΔͱҎԼͷΑ͏ͳද͕ࣔ͞ΕΔ git status README.md
ϑΝΠϧ͕͞Ε͍ͯͳ͍ ݱࡏ master ϒϥϯνʹ͍Δ ࠔͬͨΒ͙͢ʹHJUTUBUVTΛ͢Δ͜ͱʂ ݱࡏʹର͢Δඞཁͳ͜ͱΛڭ͑ͯ͘ΕΔ
Ճͨ͠ϑΝΠϧΛεςʔδʹ Ҡಈ͢Δ • git add ίϚϯυͰϑΝΠϧΛՃ͢Δ git add README.md εςʔδʹҠಈ͍ͨ͠
ϑΝΠϧ໊Λࢦఆ͢Δ
ঢ়ଶΛ֬ೝ͢Δ • ࠶ͼ git status ίϚϯυͰঢ়ଶΛ֬ೝ͢Δ • ͢ΔͱҎԼͷΑ͏ͳද͕ࣔ͞ΕΔ git status
README.md ϑΝΠϧ͕ίϛοτରʹͳͬͨ
ίϛοτ͢Δ • git commit ίϚϯυͰίϛοτ͢Δ git commit -m 'READMEΛՃͨ͠' NΦϓγϣϯίϛοτϝοηʔδΛࢦఆ͢Δ
NΦϓγϣϯΛࢦఆ͠ͳ͍߹ɺ DPSFFEJUPSͰઃఆͨ͠ΤσΟλΛىಈ͢Δ ίϛοτ ϝοηʔδΛ ࢦఆ͢Δ
ঢ়ଶΛ֬ೝ͢Δ • ࠶ͼ git status ίϚϯυͰঢ়ଶΛ֬ೝ͢Δ • ͢ΔͱҎԼͷΑ͏ͳද͕ࣔ͞ΕΔ git status
ίϛοτର͕ͳ͘ͳͬͨ͜ͱ͕Θ͔Δ
ίϛοτΛ֬ೝ͢Δ • git log ίϚϯυͰίϛοτϩάΛ֬ೝ͢Δ • ͢ΔͱҎԼͷΑ͏ͳද͕ࣔ͞ΕΔ git log ίϛοτϝοηʔδͱ
୭͕͍ͭίϛοτ͔͕ͨ͠Θ͔Δ
࠶ϑΝΠϧΛมߋ͢Δ • README.md ʹҎԼͷςΩετΛՃ͢Δ # Git ॳΊͯͷ Git ϑΝΠϧͰ͢ɻ
ଓ͍ͯՃͷίϛοτΛߦ͍·͢ɻ ՃߦͷςΩετ ֯εϖʔε 2 ݸΛ ޙΖʹೖΕΔ
ࠩΛ֬ೝ͢Δ • git diff ίϚϯυͰࠩΛ֬ೝ͢Δ Ҏલͷ README.md ͱ ݱࡏมߋͨ͠ README.md
ͷࠩΛදࣔͯ͘͠ΕΔ
࠶εςʔδʹՃͯ͠ ίϛοτ͢Δ • ࠶ git add ίϚϯυͰεςʔδʹՃ͠ɺ git commit ίϚϯυͰίϛοτ͢Δ
git add README.md git commit -m 'READMEʹίϛοτจΛՃͨ͠'
ίϛοτΛ֬ೝ͢Δ • ࠶ git log ίϚϯυͰίϛοτϩάΛ ֬ೝ͢Δ • ͢ΔͱҎԼͷΑ͏ͳද͕ࣔ͞ΕΔ ίϛοτ͕Ճ͞Ε͍ͯΔ͜ͱ͕
Θ͔Δ
git add ίϚϯυͷิ • git add . ͰΧϨϯτσΟϨΫτϦҎԼͷϑΝΠϧશͯ ΛεςʔδʹҠಈ͢Δ •
-A ·ͨ --all ΦϓγϣϯͰมߋͨ͠ϑΝΠϧ৽نͰ ࡞ͨ͠ϑΝΠϧΛશͯεςʔδʹҠಈ͢Δ • εςʔδʹҠಈ͍ͨ͠ϑΝΠϧΛ֬ೝ͍ͨ͠߹ɺ git status Ͱ֬ೝ͠ͳ͕Β֤ϑΝΠϧΛҠಈ͢Δͱྑ͍ git add . ϐϦΦυΧϨϯτσΟϨΫτϦΛҙຯ͢Δ
git commit ίϚϯυͷิ • git commit . ͰσΟϨΫτϦԼͷطͷ ϑΝΠϧΛશͯίϛοτ͢Δ
※ ৽نϑΝΠϧؚ·ͳ͍ • git commit -a طͷϑΝΠϧΛશͯίϛοτ͢Δ ˞ ৽نϑΝΠϧؚ·ͳ͍ • git commit -am '<MSG>' Ͱมߋͷ͋ΔϑΝΠϧΛίϛοτ ϝοηʔδ͖ͰίϛοτͰ͖Δ
͜Ε·Ͱͷ·ͱΊ ͦͷ1 • git init : ϩʔΧϧϦϙδτϦΛ࡞͢Δ • git add
: εςʔδϯάʹϑΝΠϧΛՃ͢Δ • git commit : ͦͷ࣌Λه͢Δ • git diff : ࠩΛݟΔ • git status : ݱࡏͷঢ়ଶΛݟΔ • git log : ݱࡏͷίϛοτϩάΛݟΔ
ϒϥϯνΛ࡞ͯ͠ Ϛʔδͯ͠ΈΑ͏
ϒϥϯν࡞ͯ͠Ϛʔδ͢ΔྲྀΕ 1 2 3 merge 2 3 task ϒϥϯν master
ϒϥϯν
ϒϥϯνΛ࡞͢Δ • git branch ίϚϯυͰϒϥϯνΛ࡞͢Δ git branch task1 ࡞͍ͨ͠ϒϥϯν໊Λ ࢦఆ͢Δ
• git branch ίϚϯυͰϒϥϯνΛ֬ೝ͢Δ • ͢ΔͱҎԼͷΑ͏ͳද͕ࣔ͞ΕΔ ࡞ͨ͠ϒϥϯνΛ֬ೝ͢Δ git branch task1
ϒϥϯν͕࡞͞Ε͍ͯΔ͜ͱ͕Θ͔Δ
࡞ͨ͠ϒϥϯνʹΓସ͑Δ • git checkout ίϚϯυͰϒϥϯνΛ Γସ͑Δ git checkout task1 Γସ͍͑ͨϒϥϯν໊Λ
ࢦఆ͢Δ
• git branch ίϚϯυͰϒϥϯνΛ֬ೝ͢Δ • ͢ΔͱҎԼͷΑ͏ͳද͕ࣔ͞ΕΔ • ͘͠ git status
ίϚϯυͰ֬ೝͰ͖Δ Γସ͑ͨϒϥϯνΛ֬ೝ͢Δ git branch task1 ϒϥϯνΓସΘ͍ͬͯΔ͜ͱ͕Θ͔Δ task1 ϒϥϯνͰ͋Δ͜ͱ͕Θ͔Δ
master ϒϥϯνʹΔ • git checkout ίϚϯυͰ master ϒϥϯνʹ Γସ͑Δ git
checkout master master ϒϥϯνΛࢦఆ͢Δ
ϒϥϯνΛ࡞ͯ͠Γସ͑Δ • git checkout ίϚϯυͰϒϥϯνΛ࡞ͯ͠ Γସ͑Δ git checkout -b task2
࡞ۀΛ࢝ΊΔͱ͖ɺ checkout ίϚϯυͱ -b ΦϓγϣϯΛ Α͘͏ Cࢦఆͨ͠ϒϥϯνΛ࡞ͯ͠Γସ͑Δ
ϑΝΠϧΛมߋ͢Δ • README.md ʹҎԼͷςΩετΛՃ͢Δ # Git ॳΊͯͷ Git ϑΝΠϧͰ͢ɻ
ଓ͍ͯՃͷίϛοτΛߦ͍·͢ɻ ଓ͍ͯϚʔδΛߦ͍·͢ɻ ՃߦͷςΩετ ֯εϖʔε 2 ݸΛ ޙΖʹೖΕΔ
εςʔδʹՃͯ͠ίϛοτ͢Δ • git commit -am ίϚϯυͰίϛοτ͢Δ git commit -am 'READMEʹϚʔδจΛՃͨ͠'
master ϒϥϯνʹΔ • git checkout ίϚϯυͰ master ϒϥϯνʹ Γସ͑Δ git
checkout master
master ϒϥϯνʹมߋΛ Ϛʔδ͢Δ • git merge ίϚϯυͰ master ϒϥϯνʹ task2
ϒϥϯνΛ౷߹͢Δ git merge task2 ϚʔδݩͷϒϥϯνΛࢦఆ͢Δͱ ݱࡏͷϒϥϯνʹϚʔδ͞ΕΔ
ίϛοτΛ֬ೝ͢Δ • git log ίϚϯυͰίϛοτϩάΛ֬ೝ͢Δ • ͢ΔͱҎԼͷΑ͏ͳද͕ࣔ͞ΕΔ
task2 ͷίϛοτ͕ Ճ͞Ε͍ͯΔ͜ͱ͕Θ͔Δ
͜Ε·Ͱͷ·ͱΊ ͦͷ2 • git branch : ϒϥϯνΛ࡞ͨ͠Γɺϒϥϯν Λ֬ೝͨ͠Γ͢Δ • git
checkout : ϒϥϯνΛΓସ͑Δ • git merge : ϒϥϯνಉ࢜ΛϚʔδ͢Δ
ϦϞʔτϦϙδτϦͱ ࿈ܞͯ͠ΈΑ͏
ϦϞʔτϦϙδτϦͱ࿈ܞ͢ΔྲྀΕ ϩʔΧϧϦϙδτϦ ϦϞʔτϦϙδτϦ ϓογϡ ϓϧ ϩʔΧϧϦϙδτϦʹ ίϛοτ͢Δ
ϦϞʔτϦϙδτϦΛ࡞͢Δ • GitHub ͷτοϓϖʔδʹΞΫηεͯ͠ɺNew repository ͔ΒϦϙδτϦΛ࡞͢Δ New repository Λ ΫϦοΫ
Create repository Λ ΫϦοΫ git-handson ͱ ೖྗ
push ίϚϯυΛ ίϐʔͯ͠λʔϛφϧ ͔Β࣮ߦ͢Δ
push ͯ͠ϒϥβΛ ߋ৽͢Δͱϓογϡ͕ ͍ྃͯ͠Δ
git pull • νʔϜ։ൃ͍ͯ͠Δ߹ʹɺϦϞʔτϦϙδτϦ͕ ߋ৽͞ΕΔͷͰมߋΛऔΓࠐΉͨΊʹ git pull ίϚϯυͰ ϦϞʔτϦϙδτϦ͔ΒϩʔΧϧϦϙδτϦʹมߋΛ औΓࠐΉ࣌ʹ༻͢Δ
˞ checkout ͢Δͱ͖ݱࡏͷϒϥϯνΛݩʹϒϥϯνΛ ࡞͢ΔͷͰ git pull Λͯ͠࠷৽ʹ͓ͯ͘͠ඞཁ͕͋Δ git pull origin master origin : ϦϞʔτϦϙδτϦͷผ໊
git clone • ϦϞʔτϦϙδτϦ͕࡞͞Ε͍ͯΔ߹ʹ git clone ίϚϯυͰϦϞʔτϦϙδτϦΛ ϩʔΧϧʹऔಘ͢Δ࣌ʹ༻͢Δ git clone
https://github.com/takasp/example.git ϦϙδτϦͷ URL Λࢦఆ͢Δ
GitHub Ͱͷ࣮ࡍͷ࡞ۀϑϩʔ master ϒϥϯν feature ϒϥϯνͳͲ ᶃ pull ͯ͠ ࠷৽ʹ͢Δ
ᶅ ίϛοτ͢Δ ᶆ GitHub ʹ push ͢Δ ᶄ checkout ͢Δ ᶇ Pull Request Λ͛Δ NBTUFSϒϥϯνΛ ࠷৽ʹͨ͠ঢ়ଶͰ NBTUFSϒϥϯν͔Β DIFDLPVU͠ͳ͍ͱ ݹ͍··ͳͷͰҙ
͜Ε·Ͱͷ·ͱΊ ͦͷ3 • git push : ϦϞʔτϦϙδτϦʹϓογϡ͢Δ • git pull
: ϦϞʔτϦϙδτϦ͔ΒมߋΛऔಘ ͢Δ • git clone : ϦϞʔτϦϙδτϦ͔ΒϩʔΧϧʹ ϦϙδτϦΛऔಘ͢Δ
ԋश
ԋश • άϧʔϓΛ࡞Γ·͢ • νʔϜͷҰਓ͕ GitHub ্ʹϦϙδτϦΛ ࡞ͯ͠ɺΫϩʔϯ͠·͢ • Git
ͷίϚϯυͷҙຯΛҰͭͣͭௐ·ͱΊͯɺ ίϛοτɺϓογϡ͠߹͍·͠ΐ͏
͍͞͝ʹ
Git ։ൃ͢Δ্Ͱͷ σϑΝΫτελϯμʔυ
ԿࣄखΛಈ͔͞ͳ͍ͱ ֮͑ΒΕͳ͍ͷͰɺ ࣗͷखΛಈ͔֮ͯ͑͠Α͏
·ͱΊ
·ͱΊ • Git ͷ֓ཁ Git ΛͬͨྲྀΕΛ͑ͨ • Git ͷίϚϯυʹ৮Εͨ •
Git ΛͬͯखΛಈ͔ͯ͠Έͨ • ։ൃ͢Δ্Ͱ Git σϑΝΫτελϯμʔυ
Part 1 ͓ΘΓ
Appendix
ࢀߟจݙ • Git͕ɺ͓͠Ζ͍΄ͲΘ͔Δجຊͷ͍ํ33 • https://ja.wikipedia.org/wiki/Git • https://git-scm.com/book/ja/v1/͍࢝ΊΔ-࠷ॳͷGitͷߏ • https://qiita.com/uasi/items/69368c17c79e99aaddbf •
https://qiita.com/takeo-asai/items/9bc7e25cd94cd8c9adee • http://www-creators.com/archives/2106 • http://kimromi.hatenablog.jp/entry/2015/08/04/082357