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-inside
Search
Hiroyuki Morita
May 16, 2017
Programming
0
240
git-inside
.git の中身を見るという内々勉強会用の資料です
(画像などは入っていないので後日差し替え予定)
Hiroyuki Morita
May 16, 2017
Tweet
Share
More Decks by Hiroyuki Morita
See All by Hiroyuki Morita
Rubyistなら知っておきたい継承の話 / The inheritance for Rubyist
chiastolite
4
1.4k
esaを使って暗黙知を減らす取り組み
chiastolite
2
4.1k
vagrant-itamae
chiastolite
1
1.5k
sushi for common people
chiastolite
0
320
Social Coding with GitHub
chiastolite
0
140
Low Level Git
chiastolite
0
90
about Immutable Infrastructure
chiastolite
0
86
Other Decks in Programming
See All in Programming
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
100
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
470
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
1.9k
EventSourcingの理想と現実
wenas
6
2.3k
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
100
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
610
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
Featured
See All Featured
Unsuck your backbone
ammeep
668
57k
Producing Creativity
orderedlist
PRO
341
39k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Rails Girls Zürich Keynote
gr2m
94
13k
Facilitating Awesome Meetings
lara
50
6.1k
The Invisible Side of Design
smashingmag
298
50k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
RailsConf 2023
tenderlove
29
900
Transcript
࣮ߦ͠ͳ͕ΒΈΔ .gitͷத
త • gitͷΦϒδΣΫτཧͷΈΛཧղ͢Δ • ίϛοτ͔ΒͭΒͳΔάϥϑߏ • branch/tagͳͲͷϦϑΝϨϯεߏ • ߏΛΘ্͔ͬͨͰίϚϯυΛݟΔ͜ͱͰཧղ͕ਂ·Δ •
Կ͕͓͖͍ͯΔ͔Θ͔Δ͔Βɺݩʹ͢ํ๏Θ͔Δ
git init ΛΈΔ
git initޙͷ.git $ git init $ ls -p .git/ HEAD
config description hooks/ info/ objects/ refs/ $ find .git/objects .git/objects .git/objects/info .git/objects/pack
git add & commitΛΈΔ $ echo 'Hello world!' > hello_world.txt
$ git add hello_world.txt $ git commit -m 'First Commit' [master (root-commit) 27baa2b] First Commit 1 file changed, 1 insertion(+) create mode 100644 hello_world.txt
.git/objectsͷத $ find .git/objects .git/objects .git/objects/27 .git/objects/27/baa2b9da21b4485966c2a97268876b189331e9 .git/objects/9b .git/objects/9b/e385e79f8f3e0870e48474809dab293843aece .git/objects/cd
.git/objects/cd/0875583aabe89ee197ea133980a9085d08e497 .git/objects/info .git/objects/pack 3ͭϑΝΠϧ͕૿Ճ
3ͭϑΝΠϧ͕૿͑ͨ • 1͓ͭͦΒ͘ςΩετϑΝΠϧ • Γͷ2ϑΝΠϧʹԿ͕?
Ͱݟ͍͖ͯ·͢
# ίϛοτޙͷϝοηʔδ [master (root-commit) 27baa2b] First Commit ~~~~~~~ 1 file
changed, 1 insertion(+) create mode 100644 hello_world.txt # .gitҎԼͷϑΝΠϧ .git/objects/27/baa2b9da21b4485966c2a97268876b189331e9 ~~~~~~~~ SHA-1͕Ұக͍ͯ͠Δ
27baa2b(ུ)ͷதΛݟͯΈΔ $ git cat-file -t 27baa2b9da21b4485966c2a97268876b189331e9 commit ͜ͷϑΝΠϧͷλΠϓcommit
27baa2b(ུ)ͷதΛݟͯΈΔ தʹ͜Μͳใ͕อଘ͞Ε͍ͯΔ $ git cat-file -p 27baa2b9da21b4485966c2a97268876b189331e9 tree 9be385e79f8f3e0870e48474809dab293843aece author
chiastolite <
[email protected]
> 1494611014 +0900 committer chiastolite <
[email protected]
> 1494611014 +0900 First Commit
27baa2b(ུ)ͷதΛݟͯΈΔ • author ͱ λΠϜελϯϓ • commiter ͱ λΠϜελϯϓ •
ίϛοτϝοηʔδ • tree?
# commitΦϒδΣΫτͷத tree 9be385e79f8f3e0870e48474809dab293843aece # .gitҎԼͷϑΝΠϧ .git/objects/9b/e385e79f8f3e0870e48474809dab293843aece ·ͨSHA-1͕Ұக͍ͯ͠Δ
9be385e(ུ)ͷதΛݟͯΈΔ $ git cat-file -t 9be385e79f8f3e0870e48474809dab293843aece tree ͜ͷϑΝΠϧͷλΠϓtree
9be385e(ུ)ͷதΛݟͯΈΔ $ git cat-file -p 9be385e79f8f3e0870e48474809dab293843aece 100644 blob cd0875583aabe89ee197ea133980a9085d08e497 hello_world.txt
9be385e(ུ)ͷதΛݟͯΈΔ • mode • ύʔϛογϣϯͱ͔ͦ͏͍͏ͷ • ϑΝΠϧ໊ • SHA-1 •
blob?
# treeΦϒδΣΫτͷத 100644 blob cd0875583aabe89ee197ea133980a9085d08e497 hello_world.txt # .gitҎԼͷϑΝΠϧ .git/objects/cd/0875583aabe89ee197ea133980a9085d08e497 ·ͨSHA-1͕Ұக͍ͯ͠Δ
cd08755(ུ)ͷதΛݟͯΈΔ $ git cat-file -t cd0875583aabe89ee197ea133980a9085d08e497 blob ͜ͷϑΝΠϧͷλΠϓblob
cd08755(ུ)ͷதΛݟͯΈΔ $ git cat-file -p cd0875583aabe89ee197ea133980a9085d08e497 Hello world! Α͏͘தʹḷΓ͍ͭͨ
͜͜·Ͱͷ·ͱΊ git • 3छྨͷλΠϓͷΦϒδΣΫτͰཧͯ͠Δ • commmit • tree •
blob • ֤ΦϒδΣΫτSHA-1Ͱཧ͞Ε͍ͯͯΦϒδΣΫτಉ࢜Λ ࢀর͍ͯ͠Δ
ਤʹ͢Δͱ͜Μͳײ͡
࣍ʹ # ϑΝΠϧΛαϒσΟϨΫτϦʹίϐʔ $ mkdir subdir $ cp hello_world.txt subdir/sample.txt
$ git add subdir/sample.txt # ݩϑΝΠϧΛॻ͖͑ $ echo 'Hello world!!' > hello_world.txt $ git add -u hello_world.txt $ git commit -m'update'
ࠓͷঢ়ଶ !"" hello_world.txt #=> Hello world!! #"" subdir #"" sample.txt
#=> Hello world!
commitͷத $ git cat-file -p HEAD tree 95aaf923a1c8171c9ec05225a3911a0dbeb53d6f parent 27baa2b9da21b4485966c2a97268876b189331e9
author chiastolite <
[email protected]
> 1494611946 +0900 committer chiastolite <
[email protected]
> 1494611946 +0900 update • parent͕Ճ͞Ε͍ͯΔ • 1ͭલͷcommitͷSHA-1
treeͷத git cat-file -p 95aaf923a1c8171c9ec05225a3911a0dbeb53d6f 100644 blob b297683f36d0557a8ef83506beda7b80e233723d hello_world.txt 040000
tree 601df7ed8aabbd875614ba3a301fe344e5c45ae2 subdir • த͕มΘͬͨhello_world.txtͷSHA-1͕มԽ • treeͷதʹtree͕
αϒπϦʔͷத git cat-file -p 601df7ed8aabbd875614ba3a301fe344e5c45ae2 100644 blob cd0875583aabe89ee197ea133980a9085d08e497 sample.txt •
sample.txt࠷ॳͷίϛοτͷhello_world.txtͱಉ͡SHA-1
͜͜·Ͱ • commitΛ͢Δͱݩcommitͷࢀর͕͓͖Δ • 1όΠτϑΝΠϧ͕มΘΕSHA1͕มΘΔ • SHA1͕Ͱ͖Δͱ͍͏͜ͱΦϒδΣΫτ͕1ͭੜ͞Ε͍ͯ Δ • gitͰࠩͰཧ͕͞Ε͍ͯͳ͍
• ϑΝΠϧ໊͕มΘͬͯத͕ҰॹͳΒSHA1มΘΒͳ͍
ਤʹ͢Δͱ͜Μͳײ͡
SHA-1ͷ͖·Γ͔ͨ • த(+ΦϒδΣΫτͷtype)͔Β Ұҙʹ ܾ·͍ͬͯΔ • ͩΕ͕ͲͷλΠϛϯάͰHello world!ͯ͠SHA-1 cd0875583aabe89ee197ea133980a9085d08e497 $
git hash-object -t blob <(echo 'Hello world!') cd0875583aabe89ee197ea133980a9085d08e497 ৄ͘͠ Gitsha1ͷܭࢉΛͲͷΑ͏ʹ͍ͬͯΔͷ͔ · DQNEO ىۀه ͕ৄ͍͠
refs
refs • master • branch • tag • HEAD(=@) •
ORIG_HEAD ͳͲͳͲ
.git/HEAD ݱࡏࢀর͍ͯ͠Δͱ͜Ζ $ cat .git/HEAD ref: refs/heads/master ࠓmasterϒϥϯνΛݟ͍ͯΔΆ͍
$ cat .git/refs/heads/master 2e7a843cd5706b128e13f06cf7572cda27afa0a7 $ git log commit 2e7a843cd5706b128e13f06cf7572cda27afa0a7 (HEAD
-> master) • Ұக • masterϒϥϯν͕ͲͷίϛοτΛࢦ͍ͯ͠Δ͔ܾΊ͍ͯΔ
ͨΊ͠ʹ $ mv .git/refs/heads/{master, hogehoge} $ cat 'ref: refs/heads/hogehoge' >
.git/HEAD ͱΔͱ git branch -m hogehoge͕Ͱ͖Δ
branch $ git branch test_branch $ cat .git/refs/heads/test_branch 2e7a843cd5706b128e13f06cf7572cda27afa0a7 •
ϒϥϯνΛ͚ͬͨͩͩͱSHA-1͔ΘΒͳ͍ • ͜ͷ࣌ͰmasterͱԿҧ͍͕ͳ͍ • ϒϥϯνͲͪΒ͔ͱ͍͏ͱϙΠϯλʔϥϕϧతײ֮ • ݴ͏΄ͲࢬΆ͘ͳ͍
branchΛࢀর͍ͯ͠Δঢ়ଶͰίϛοτΛͯ͠ΈΔ $ git checkout test_branch Switched to branch 'test_branch' $
git rm -r subdir rm 'subdir/sample.txt' $ git commit -m'Remove sub dir'
$ cat .git/refs/heads/test_branch 508b59bff7ae9af5b516d873eea32c9446540c09 $ git cat-file -p 686bcfe77bf1c43eb8d4e2aa75075e6d6e7e961e tree
19e6ae1b6538047780cd1d44a10fdb0685f15705 parent 2e7a843cd5706b128e13f06cf7572cda27afa0a7 author chiastolite <
[email protected]
> 1494613438 +0900 committer chiastolite <
[email protected]
> 1494613438 +0900 Remove sub dir ίϛοτ͢Δref͕มߋ͞ΕΔ
mergeͯ͠ΈΔ $ git checkout test_branch $ git merge test_branch --no-ff
Removing subdir/sample.txt Merge made by the 'recursive' strategy. subdir/sample.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 subdir/sample.txt
$ git cat-file -p master tree 19e6ae1b6538047780cd1d44a10fdb0685f15705 parent 2e7a843cd5706b128e13f06cf7572cda27afa0a7 parent
508b59bff7ae9af5b516d873eea32c9446540c09 author chiastolite <
[email protected]
> 1494613595 +0900 committer chiastolite <
[email protected]
> 1494613595 +0900 Merge branch 'test_branch' • parent͕2ͭ • masterͩͬͨͱ͜Ζ • test_branch
ਤ
rebaseͯ͠ΈΔ (͜ͷ··ͩͱ্ख͍͔͘ͳ͍ͷͰmasterΛmergeલʹͯ͠ί ϛοτΛՃ͓ͯ͘͠)
$ git rebase master First, rewinding head to replay your
work on top of it... Applying: Remove sub dir $ cat .git/refs/heads/test_branch 0957492b728dbf7854f46c30be6670fcf29b61a6 ৽͍͠SHA-1
rebaseલͷίϛοτ? $ git log 508b59bff7ae9af5b516d873eea32c9446540c09 commit 508b59bff7ae9af5b516d873eea32c9446540c09 Author: chiastolite <
[email protected]
>
Date: Sat May 13 03:23:58 2017 +0900 Remove sub dir ී௨ʹΞΫηεͰ͖Δ rebaseͯ͠ίϛοτ͕ফ͑ͨΓ͠ͳ͍
ਤ
͓͖͍֮͑ͯͨ͜ͱ • gitͰίϛοτ͕ফ͑Δ͜ͱͳ͍ • (ྫ֎తʹ)git gcίϚϯυͷΈ • ͳͷͰؾܰʹrebasemerge͔ͯͬͨ͠Βͦ͏
ϦϞʔτͷѻ͍ • gitͰϦϞʔτϦϙδτϦͷૢ࡞Λग़དྷΔͷҎԼͷίϚϯυͷ Έ (set-remote ઃఆ͢Δ͚ͩͳͷͰૢ࡞Ͱ͖ͳ͍) • fetch • push
• pull෦Ͱfetch + (merge or rebase) ΛݺΜͰ͍Δ
• fetch • ϦϞʔτϦϙδτϦͷঢ়ଶΛϩʔΧϧʹ࣋ͬͯ͘Δ • push • ϩʔΧϧͷ༰Λࢦఆͨ͠ϒϥϯνʹૹΔ
git remote ײ֮తʹϨΠϠʔߏͱࣅͯΔؾ͕ͯ͠Δ • ϩʔΧϧͱϦϞʔτͱ͍͏ϨΠϠʔ • fetch͢Δ͜ͱͰϩʔΧϧͷϦϙδτϦϨΠϠʔʹϦϞʔτͷ ༰Λө͢ΔΈ͍ͨͳ • ౷߹͡Όͳ͍ͷ͕ҧ͏ͱ͜Ζ
ਤʹ͢Δͱ͜Μͳײ͡?
origin/masterͱorigin masterͷҧ͍ • origin master • originʹઃఆͨ͠ϦϞʔτϦϙδτϦͷmasterϒϥϯν • ϦϞʔτͷ •
origin/master • originʹઃఆͨ͠ϦϞʔτϦϙδτϦͷmasterϒϥϯνͷref Λखݩʹίϐʔͨ͠ͷ • ϩʔΧϧͷ
• origin/master࠷ޙʹfetchͨ͠ͱ͖ͷ origin ͷ masterͷঢ়ଶ ͳͷͰϦϞʔτͷ࠷৽ͱݶΒͳ͍ • ϦϞʔτʹै͠Α͏ͱ rebase origin/master͢Δ߹
ࣄ લʹfetchͨ͠΄͏͕Α͍
Α͘͏Φϓγϣϯ • add • -u • -p • commit •
--ammend • -C • -v
Α͘͏Φϓγϣϯ • stash • --keep-index • push • --force-with-lease •
rebase • -i • --autosquash(git commit --fixupલఏ)
Conditional configuration(>= Git 2.13) $ cat ~/.gitconfig [includeIf "gitdir:~/work/"] path
= .gitconfig-work [includeIf "gitdir:~/play/"] path = .gitconfig-play $ cat ~/.gitconfig-work [user] name = Hiroyuki Morita email =
[email protected]
$ cat ~/.gitconfig-play [user] name = chiastolite email =
[email protected]
ࣄͱϓϥΠϕʔτɺࣄͱOSSͷઃఆΛ͚ΒΕΔ