$30 off During Our Annual Pro Sale. View Details »
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
watsonx.ai Dojo #4 生成AIを使ったアプリ開発、応用編
oniak3ibm
PRO
1
260
AWS AppSyncを用いた GraphQL APIの開発について - NIFTY Tech Talk #22
niftycorp
PRO
0
110
CSC509 Lecture 13
javiergs
PRO
0
130
カンファレンスの「アレ」Webでなんとかしませんか? / Conference “thing” Why don't you do something about it on the Web?
dero1to
1
150
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
140
.NET 9アプリをCGIとして レンタルサーバーで動かす
mayuki
0
720
The rollercoaster of releasing an Android, iOS, and macOS app with Kotlin Multiplatform | droidcon Italy
prof18
0
120
我々のデザインシステムは Chakra v3 にアップデートします
shunya078
2
1.5k
Leverage LLMs in Java with LangChain4j and Quarkus
hollycummins
0
110
競技プログラミングで 基礎体力を身につけよう / You can get basic skills through competitive programming
mdstoy
0
130
.NET Conf 2024の振り返り
tomokusaba
0
170
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
200
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
1
210
Gamification - CAS2011
davidbonilla
80
5k
Teambox: Starting and Learning
jrom
133
8.8k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
How to Think Like a Performance Engineer
csswizardry
20
1.2k
A designer walks into a library…
pauljervisheath
204
24k
Designing the Hi-DPI Web
ddemaree
280
34k
The Cost Of JavaScript in 2023
addyosmani
45
6.9k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Raft: Consensus for Rubyists
vanstee
136
6.7k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
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