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
情報漏洩させないための設計
kubotak
3
300
良いユニットテストを書こう
mototakatsu
8
2.7k
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
550
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
5
700
バグを見つけた?それAppleに直してもらおう!
uetyo
0
180
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
3
480
Spatial Rendering for Apple Vision Pro
warrenm
0
110
命名をリントする
chiroruxx
1
410
Effective Signals in Angular 19+: Rules and Helpers
manfredsteyer
PRO
0
110
Kaigi on Railsに初参加したら、その日にLT登壇が決定した件について
tama50505
0
100
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
830
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
169
14k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
Mobile First: as difficult as doing things right
swwweet
222
9k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
KATA
mclloyd
29
14k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
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