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 & GitHub Tips
Search
Yuku TAKAHASHI
June 01, 2014
Programming
88
15k
入門書には載ってない Git & GitHub Tips
第一回 GitHub Kaigi で発表した資料です。
Yuku TAKAHASHI
June 01, 2014
Tweet
Share
More Decks by Yuku TAKAHASHI
See All by Yuku TAKAHASHI
こんな感じでデータパイプライン作ってます 2019年春
yuku
2
4.3k
Other Decks in Programming
See All in Programming
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
Ethereum_.pdf
nekomatu
0
470
Click-free releases & the making of a CLI app
oheyadam
2
120
Remix on Hono on Cloudflare Workers
yusukebe
1
300
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
初めてDefinitelyTypedにPRを出した話
syumai
0
420
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
Jakarta EE meets AI
ivargrimstad
0
690
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
200
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
Featured
See All Featured
Done Done
chrislema
181
16k
Building Your Own Lightsaber
phodgson
103
6.1k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Practical Orchestrator
shlominoach
186
10k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
RailsConf 2023
tenderlove
29
900
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Transcript
ೖॻʹࡌͬͯͳ͍ Git&GitHub Tips ·ͨɺ͍͔ʹͯ͠ʑPRΛ͍͍ͯ͞Δ͔ ߴڮါٱʢgh:yuku-tʣ
ߴڮါٱ ͔ͨ͠ Ώ͏͘ yuku_t yuku-t GitHub ͱͷೃΕॳΊ 2013/02 GitHubۀऀ&CIOͱژ؍ޫΛָ͠Ή 2013/07
GitHubͷϓϥΠϕʔτϧʔϜͰେϦʔά؍ઓ͢Δ 2014/06 GitHub KaigiͰ͢ CTO @ Increments
ఏڙ
OAuth ͏͙͢ 20000 4
͢͜ͱ&Δ͜ͱ • Qiitaʹࡌͬͯͨ • GitHub Cheat Sheetʹࡌͬͯͳ͍ • ʮೖ Gitʯʹग़ͯ͜ͳ͍
• ͋ͱGitHubΛͬͨσϞ 5 ʘ ࡌͬͯͳ͍Α ʗ
Conflict
ίϯϑϦΫτൃੜ࣌ͷ % git merge master 7 HEAD master <<<<<<< HEAD
topic branch ======= master >>>>>>> master !!! ίϯϑϦΫτ͢ΔͱHEADͱϚʔδର͕ॻ͖ग़͞ΕΔ ➡ͱͷঢ়ଶ͕͔Βͳͯ͘ࠔΔ͜ͱ͕͋Δ
ڞ௨ͷઌͷใΛॻ͖ग़͢ 8 http://qiita.com/hchbaw/items/1191c2627307a4673b1b <<<<<<< HEAD topic branch ||||||| merged common
ancestors original ======= master >>>>>>> master HEAD master • ڞ௨ͷઌͷঢ়ଶॻ͖ग़͞ΕΔΑ͏ʹͳΔ - ௨ৗͷΤσΟλͰίϯϑϦΫτղফͯ͠Δਓʹศར - mergetoolΛ͍ͬͯΔਓʹಛʹϝϦοτͳ͍ % git config --global merge.conflictstyle diff3
git stash
git stash save / pop • indexͷใ͕ܽམ ➡ file͕શମ͕unstagedʹ 10
• track͞Ε͍ͯͳ͍ϑΝΠϧ ͞ΕΔ ➡ readme͕͍ͬͯΔ • indexͨ͠ͷstash͞ΕΔ ➡ fileʹaddͨ͠෦stash ‣ -q,--quiet ඪ४ग़ྗΛ੍͢Δ
--all --include-untracked --keep-index -u, --include-untracked • track͞Ε͍ͯͳ͍ ϑΝΠϧstash͢Δ ➡ readmestash͞ΕΔ
-a, --all • ignoredͳϑΝΠϧશ෦ 11 -k, --keep-index • index treeΛͦͷ··͢ ➡ fileͷadd͞ΕͨՕॴ͕ ͍ͬͯΔ http://qiita.com/ton1517/items/9888a78f6b063e748558
git stash pop --index --index • working tree͚ͩͰͳ͘index tree෮ݩ͢Δ ➡
fileͷadd͞Εͨঢ়ଶ͕෮ݩ͞Ε͍ͯΔ 12 http://qiita.com/ton1517/items/9888a78f6b063e748558
શ͘৽͍͠working directory͕ཉ͍͠ • git stash -uͰશͯstashͰ͖Δ͚Ͳɺ1͔Β ৽͍͠working directory͕ཉ͘͠ͳΔͱ͖͋Δ ! •
.gitσΟϨΫτϦͷத͕γϯϘϦοΫϦϯΫͰ ͭͳ͕͍ͬͯΔͷͰશͯͷΦϒδΣΫτ͕ಉظ͢Δ ➡ stashಉظ͢ΔͷͰnew-workdirͰॻ͍ͨίʔυΛ stash popͰ؆୯ʹऔΓࠐΊΔ ʦ༨ஊʧgit-core/contribʹศརͳεΫϦϓτ͕৭ʑ ๏ ಛʹdiff-highlightͬͯͳ͍ਓਓੜଛͯ͠Δ 13 http://qiita.com/yuya_presto/items/dcebbebc6b3d9cf6f542 % ln -s /path/to/git-core/contrib/workdir/git-new-workdir ~/bin % git-new-workdir . ../new-workdir % cd ../new-workdir # ৽͍͠working directory
git diff & apply
ۭനͷҧ͍͚ͩͷߦΛআ͍ͯadd ✓ ۭനҧ͍͚ͩͷίϛοτ͕ผͩͱͪΐͬͱخ͍͠ -w, --ignore-all-space • ࠩܭࢉ࣌ʹۭനจࣈΛແࢹ͢Δɻ ! --cached •
working treeΛ৮ΒͣʹindexͷΈߋ৽͢Δ 15 % git diff -w % git apply --cached < patch % git diff -w | git apply --cached http://qiita.com/yuya_presto/items/dcebbebc6b3d9cf6f542 ※ ۭനͷมߋͱଞͷมߋ͕ۙ͘ʹ͋ΔͱίϯϑϦΫτ͕ൃੜͯ͑͠·ͤΜ
git fsck
ͦͦgit fsckͱʁ • gitͷ࣮ମάϥϑ - ݸʑͷϊʔυsha1Λ͕࣋ͭ… • ͏ίϛοτʹ໊લ(ref)Λ͚ͭΔ - HEAD,
branch, tagͳͲͳͲ • refs͔ΒḷΕͳ͍ͷΰϛ • git fsckΰϛΛఆˍྻڍ͢Δ 17 ref % git fsck dangling commit ͷsha1 ※ ࣮ࡍʹΰϛΛফ͢ͷgit prune
addͯ͠commitͤͣʹreset --hardͨ͠ • ΰϛఆ͞ΕͨΦϒδΣΫτΛॻ͖ग़͢ - .git/lost-found/commit/ - .git/lost-found/other/ # ͬͪ͜
• ॻ͖ͩ͞ΕͨϑΝΠϧΛgrepͯͯ͠ͷϑΝΠϧ Λ୳ͯ͠෮ݩ͢Δ 18 http://qiita.com/yoshiori/items/6da867aa6871be694996 % git fsck --lost-found
ޡͬͯgit stash clearͨ͠ • git fsck͕ग़ྗ͢ΔϚʔδίϛοτͰsubjectʹ WIPΛؚΉͷΛྻڍ͢Δ ! • ͯͷsha1͕͔ͬͨΒgit
stash applyͰ ద༻Ͱ͖Δ 19 % git fsck | grep commit | cut -d' ' -f3 | xargs git log --merges --no-walk --grep=WIP % git stash apply <stash-sha1>
GitHub & Review
hub • CLI͔ΒGitHubΛૢ࡞͢ΔͨΊͷπʔϧ ! - ݱࡏͷϦϙδτϦΛϒϥβͰ։͘ ! - current branchΛϓϧϦΫΤετʹ͢Δ
21 http://qiita.com/yaotti/items/a4a7f3f9a38d7d3415e3 % hub pull-request % hub browse
ۭͷPullRequestΛ࡞ͬͯ࡞ۀΛՄࢹԽ • GitHubϑΝΠϧมߋແ͠ͷPullRequestΛ࡞ΕΔ - ࡞ۀΛ࢝ΊͨΒͱΓ͋͑ͣ࡞ͬͯcommit͢Δʹ push͍ͯ͘͠ - આ໌ʹλεΫΛྻڍ - पΓ͕ঢ়گΛѲ͍͢͠
22 http://qiita.com/a-suenami/items/129e09f8550f31e4c2da % git checkout -b projectx % git commit --allow-empty -m ProjectX % git push % hub pull-request # or WebUIͰPR࡞
ۭͷPullRequestΛ࡞ͬͯΩϦ൪ήοτ 23 https://twitter.com/naoya_ito/status/467245029434478592
git rebase -i --autosquash • ؾܰͳpush -fΛې͍ͯ͡ΔͱɺඍௐͷͨΊͷ ࠣࡉͳίϛοτ͕ͨ͘͞Μ࡞ΒΕͯϩά͕͔Γʹ ͘͘ͳΔ -
“squash! squashରίϛοτͷίϝϯτ” ͱίϛοτ͢Δͱinteractive rebase࣌ʹࣗಈతʹ ͍͍ײ͡ʹͯ͘͠ΕΔ • શͯͷ࡞ۀ͕ྃͨ͠ஈ֊Ͱautosquashͯ͠ ʢपΓͱҙࢥૄ௨ΛऔΓͭͭʣpush -f 24 http://qiita.com/kyanro@github/items/818012c1b1827ed48277
autosquashΛָʹ͢Δ • ৗʹautosquash͢Δ ‣ git rebase࣌ʹࣗಈͰ--autosquashΦϓγϣϯ ΛՃ͢ΔΑ͏ʹͳΔ ‣ --autosquash--interactive࣌ͷΈӨڹ͢ ΔͷͰͱΓ͋͑ͣtrueͰಛʹͳ͍ʢͣʣ
• ίϛοτϝοηʔδͷࣗಈੜ ‣ autosquash༻ͷϝοηʔδΛࣗಈੜͯ͘͠ΕΔ ‣ --fixup ΦϓγϣϯͰfixupͰ͖Δ 25 http://qiita.com/kyanro@github/items/818012c1b1827ed48277 % git config --global rebase.autosquash true % git commit --squash <commit>
ϒϥϯν໊ΛௐΔͷ͕໘͍͘͞ • ϨϏϡʔΛґཔ͞ΕͨϒϥϯνΛϩʔΧϧʹ checkout͢Δͷʹ໊લΛௐΔͷ͕໘ ! • GitHub APIͰϓϧϦΫΤετΛऔಘͯ͠ߜΓࠐΉ 26 %
prfetch|percol|cut -f3|xargs git checkout http://qiita.com/yuku_t/items/f53a9d3ea92614b0927d ͜͜Λؤுͬͯίϐϖͯͨ͠….
alias.branch-root • τϐοΫϒϥϯνͷࠜຊͷsha1͕͔ΔͱҰ࿈ͷί ϛοτʹߜΓࠐΜΉ͜ͱ͕Ͱ͖Δ ! ‣ τϐοΫϒϥϯνͷൣғͰgit log ! ‣
τϐοΫϒϥϯνͰinteractive rebase 27 [alias] branch-root = merge-base master HEAD % git log $(git branch-root)..HEAD % git rebase -i $(git branch-root) http://qiita.com/yuku_t/items/5cf770157380952e9476
ϨϏϡʔϩʔΧϧͰ • ϨϏϡʔ࣌৭ʑͳใΛࢀর͢ΔͨΊɺGitHubͷ Web UIͩͱ͗͢ΔʢGH:EͲ͏͔ͩΓ·ͤΜʣ ✓ ݸਓతʹtigਪ͠ 28 [alias] review
= !tig --reverse -w $(git branch-root)..HEAD [tig “bind”] main = B @hub browse -- commit/%(commit) diff = B @hub browse -- commit/%(commit) tree = B @hub browse -- tree/%(commit)/%(directory) blob = B @hub browse -- tree/%(commit)/%(file) - ϨϏϡʔରΛtigͰಡΈࠐΉalias ‣ --reverse Λ͚ͭΔͱGitHubͷUIͱฒͼํ͕ಉ͡ʹͳͬͯخ͍͠ - ίϝϯτWebUIͰߦ͏͔͠ͳ͍ͷͰ֘ϖʔδҠಈ͢ΔΩʔόΠϯυඞਢ
ఏڙ
ఏڙ WE ARE HIRING!! http://increments.co.jp/jobs