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
Click-free releases & the making of a CLI app
oheyadam
2
110
ヤプリ新卒SREの オンボーディング
masaki12
0
130
Outline View in SwiftUI
1024jp
1
320
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
210
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.3k
役立つログに取り組もう
irof
28
9.6k
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
280
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
330
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
170
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
4
120
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Building Applications with DynamoDB
mza
90
6.1k
Gamification - CAS2011
davidbonilla
80
5k
Documentation Writing (for coders)
carmenintech
65
4.4k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Music & Morning Musume
bryan
46
6.2k
Making Projects Easy
brettharned
115
5.9k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
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