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
Security_for_introducing_eBPF
kentatada
0
110
nekko cloudにおけるProxmox VE利用事例
irumaru
3
420
快速入門可觀測性
blueswen
0
310
急成長期の品質とスピードを両立するフロントエンド技術基盤
soarteclab
0
920
Go の GC の不得意な部分を克服したい
taiyow
2
760
Haze - Real time background blurring
chrisbanes
1
500
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
270
Criando Commits Incríveis no Git
marcelgsantos
2
170
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
900
似たもの同士のPerlとPHP
uzulla
1
130
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
190
第5回日本眼科AI学会総会_AIコンテスト_3位解法
neilsaw
0
170
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
The Language of Interfaces
destraynor
154
24k
Building Applications with DynamoDB
mza
91
6.1k
For a Future-Friendly Web
brad_frost
175
9.4k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
4 Signs Your Business is Dying
shpigford
181
21k
Statistics for Hackers
jakevdp
796
220k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Building Your Own Lightsaber
phodgson
103
6.1k
Six Lessons from altMBA
skipperchong
27
3.5k
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