Slide 1

Slide 1 text

Git ʹΑΔπʔϧ։ൃ YAPC::Asia 2014 motemen 1

Slide 2

Slide 2 text

motemen • GitHub: motemen • Twitter: motemen • Go/Vim/Git/Perl 2

Slide 3

Slide 3 text

஫ҙ Git ʹΑΔʮπʔϧ։ൃʯͰ͸ͳ͘
 ʮGit ʹΑΔπʔϧʯ։ൃͰ͢ 3

Slide 4

Slide 4 text

ͭͬͨ͘΋ͷ • ghq • git-browse-remote • git-pr-release • github-commit-status-mark • git-unify 4

Slide 5

Slide 5 text

ghq • Go • ͍͍ײ͡ʹ git clone / hg clone • ghq get • ghq look ghqΛ࢖ͬͨϩʔΧϧϦϙδτϦͷ౷Ұతɾޮ཰తͳ؅ཧʹ͍ͭͯ ghq + peco/percol 5

Slide 6

Slide 6 text

git-browse-remote • Ruby • ͍͍ײ͡ʹϒϥ΢βͰ։͘ • hub browse ΑΓͪΐͬͱݡ͍ 6

Slide 7

Slide 7 text

git-pr-release • Ruby • GitHub ͷ Pull Request Λ·ͱΊΔ 7

Slide 8

Slide 8 text

github-commit-status-mark • Go • CI ௨͔ͬͨͲ͏͔ͻͱ໨ͰΘ͔Δ 8

Slide 9

Slide 9 text

git-unify • sh • ෳ਺ͷϩʔΧϧΫϩʔϯͷ .git ҎԼ Λڞ༗ git-hsm: git submodule ͰαϒϞδϡʔϧ؅ཧͯ͠ΔͱσΟ εΫ༰ྔΛѹഭͯ͠ٽ͖ͨ͘ͳΓ·ͤΜ͔ 9

Slide 10

Slide 10 text

એ఻ऴΘΓ 10

Slide 11

Slide 11 text

ڞ௨఺ 11

Slide 12

Slide 12 text

࢖ͬͯͳ͍ • .git/** • libgit2 12

Slide 13

Slide 13 text

git-* • git help -a • > 150 commands • ͜ΕΒΛར༻͢Δ 13

Slide 14

Slide 14 text

Detailed Topics 14

Slide 15

Slide 15 text

҉໧ͷҾ਺ • Ϣʔβ͕Ծఆͯ͠Δ΋ͷ • ϦϙδτϦ • HEADʢϒϥϯνʣ • ex. git push (push.default=simple) 15

Slide 16

Slide 16 text

Ҿ਺ͷղऍ • git browse-remote [] • git browse-remote feature/cool • git browse-remote b08d29 • git browse-remote v0.2-pre1~1 • git browse-remote @{3} 16

Slide 17

Slide 17 text

Git • object (= tag/commit/tree/blob) Λࢦ͢ͳʹ͔ • SHA1 • ໊લ • ΄͔ • ૿͑Δ 17

Slide 18

Slide 18 text

͋Ε͜Ε • SHA1: 3b3ab428ec05924e9a96d16a05959150485f51a0, … • refname: “A symbolic ref name”, master, v2.0, HEAD… • λά/ϒϥϯν/ϦϞʔτ • “master” → “refs/heads/master” • “v2.0” → “refs/tags/v2.0” • “origin” → “refs/remotes/origin/HEAD” • ࣮ଶ͸ .git/ ҎԼ 18

Slide 19

Slide 19 text

͋Ε͜Ε • ^{n} • ~{n} • []@{yesterday}, @{3} • describeOutput: v0.5-3-g0829bd • :/ • …and more! git-rev-parse: SPECIFYING REVISIONS 19

Slide 20

Slide 20 text

DWIM!! • Ϣʔβ͕ԿΛݴ͍͍ͨͷ͔ • ϒϥϯνɾλάɾίϛοτ etc… • git symbolic-ref, git rev-parse, 
 git name-rev 20

Slide 21

Slide 21 text

git-browse-remote • ϒϥϯν΍λά • → github.com/.../tree/some-branch • ͦ͏Ͱͳ͍ίϛοτ • → github.com/.../commit/ bd08d29 21

Slide 22

Slide 22 text

gbr: Ҿ਺ • Ҿ਺ͳ͠ • ϒϥϯν΍λά • ίϛοτ • ͦͷଞʢϑΝΠϧͱ͔ʣ 22

Slide 23

Slide 23 text

gbr: Ҿ਺ͳ͠ • ҉໧ͷ HEAD • ϒϥϯν or λά or ίϛοτ • git symbolic-ref -q HEAD 23

Slide 24

Slide 24 text

git symbolic-ref • ݩ࢝ɺ.git/HEAD ͸ symlink • → .git/refs/heads/** • ࠓ: “ref: ” ͱ͔ • or SHA1 24

Slide 25

Slide 25 text

gbr: Ҿ਺͋Γ • git name-rev —name-only • rev ʹγϯϘϦοΫͳ໊લΛ༩͑Δ • “5d7d3957” → “remotes/origin/master” • “HEAD~3” → “tags/v0.4-pre" • git rev-parse —symbolic-full-name • refname Λ׬શ໊ʹ • “v0.4” → “refs/tags/v0.4” 25

Slide 26

Slide 26 text

“git foo-bar” • git-foo-bar Ͱఏڙ • git --exec-path ʹύε͕௨Δ 26

Slide 27

Slide 27 text

git --exec-path • ex: /usr/local/Cellar/git/2.1.0/libexec/git-core • Git ͷαϒίϚϯυͷๅݿ • ࣮ߦϏοτཱ͕ͬͯͳ͍΋ͷ΋
 → γΣϧεΫϦϓτ༻ 27

Slide 28

Slide 28 text

#!/bin/sh • “. git-sh-setup” ͔Βελʔτ • ศརؔ਺ͨͪ • Α͠ͳʹηοτΞοϓ 28

Slide 29

Slide 29 text

git-sh-setup • NONGIT_OK • SUBDIRECTORY_OK • OPTIONS_SPEC 29

Slide 30

Slide 30 text

OPTIONS_SPEC OPTS_SPEC="\! some-command [options] ...! ! some-command does foo and bar!! --! h,help show the help! ! foo some nifty option --foo! bar= some cool option --bar with an argument! baz=arg another cool option --baz with a named argument! qux?path qux may take a path argument but has meaning by itself! ! An option group Header! C? option C with an optional argument"! 30 git-rev-parse: PARSEOPT

Slide 31

Slide 31 text

OPTIONS_SPEC OPTS_SPEC="\! some-command [options] ...! ! some-command does foo and bar!! --! h,help show the help! ! foo some nifty option --foo! bar= some cool option --bar with an argument! baz=arg another cool option --baz with a named argument! qux?path qux may take a path argument but has meaning by itself! ! An option group Header! C? option C with an optional argument"! 31 git-rev-parse: PARSEOPT

Slide 32

Slide 32 text

ύε • ϑΝΠϧͷϧʔτ͔Βͷύε • .git σΟϨΫτϦͷҐஔ • ࢥͬͨ৔ॴʹͳ͍͜ͱ΋ (cf. submodule) 32

Slide 33

Slide 33 text

git rev-parse • git rev-parse --show-toplevel • τοϓσΟϨΫτϦͷઈରύε • git rev-parse --git-dir • git rev-parse --show-prefix • cwd ͔Βͷ૬ରύε 33

Slide 34

Slide 34 text

git rev-parse ͍͢͝ 34

Slide 35

Slide 35 text

GitHub • API • octokit / go-github • GitHub:Enterprise ରԠ • → ϗετ͕͋Β͔͡Ί෼͔Βͳ͍ 35

Slide 36

Slide 36 text

GH:E ϦϞʔτΛऔಘ 1. remote.origin.url 2. ݱࡏͷϒϥϯνʹରԠ͢ΔϦϞʔ τͷ URLʢݫີʹ΍Γ͍ͨਓʣ 36

Slide 37

Slide 37 text

Get ϦϞʔτ • $branch = `git symbolic-ref -q HEAD` • $remote = `git config branch.$branch.remote` • $url = `git config remote.$remote.url` 37

Slide 38

Slide 38 text

͞Βʹ • git config url..insteadOf • oldURL Λ push/fetch ͢Δ୅ΘΓʹ newURL ʹ 38

Slide 39

Slide 39 text

url..insteadOf • git config [email protected]:motemen/.insteadOf https://github.com/motemen/ • https://github.com/motemen/* ΁ͷΞΫηεΛ [email protected]:motemen/* ʹॻ͖׵͑ 39

Slide 40

Slide 40 text

Get ϦϞʔτ: ݁࿦ • git remote show -n ͯ͠ ਖ਼نදݱͰͳΜͱ͔͢Δ 40

Slide 41

Slide 41 text

ϦϞʔτ URL • [email protected]:path/to/repo.git/ • “SCP-like URL” • proto://host.xz[:port]/path/to/repo.git/ docs/git-fetch.html#URLS • git fetch-pack --diag-url 41

Slide 42

Slide 42 text

ઃఆ • YAML/JSON • git config 42

Slide 43

Slide 43 text

git config • Human readable/writable • KVS • ͋͘·Ͱݸਓઃఆ • .git/config • ~/.gitconfig 43

Slide 44

Slide 44 text

git config -f • git config -f <file> • ϓϩδΣΫτݻ༗ͷઃఆΛڞ༗ • cf. .git-pr-release 44

Slide 45

Slide 45 text

git config --get-urlmatch • URL ͝ͱʹઃఆΛมߋͰ͖Δ • git config --get-urlmatch
 ghq.vcs https://example.com/git/ # => “git” 45 [ghq]! vcs = unknown! [ghq "https://example.com/git/"]! vcs = git! [ghq "https://example.com/hg/"]! vcs = hg

Slide 46

Slide 46 text

ͪ͜Β͔Β͸Ҏ্Ͱ͢ 46

Slide 47

Slide 47 text

͓ΘΓ • ศརͳ Git αϒίϚϯυୡ • symbolic-ref / name-rev / rev-parse / git-sh-setup / config / remote • …and more • ׆༻͠·͠ΐ͏ • --help -w 47