Upgrade to Pro — share decks privately, control downloads, hide ads and more …

git-inside

 git-inside

.git の中身を見るという内々勉強会用の資料です
(画像などは入っていないので後日差し替え予定)

Hiroyuki Morita

May 16, 2017
Tweet

More Decks by Hiroyuki Morita

Other Decks in Programming

Transcript

  1. git init௚ޙͷ.git $ git init $ ls -p .git/ HEAD

    config description hooks/ info/ objects/ refs/ $ find .git/objects .git/objects .git/objects/info .git/objects/pack
  2. git add & commitΛΈΔ $ echo 'Hello world!' > hello_world.txt

    $ git add hello_world.txt $ git commit -m 'First Commit' [master (root-commit) 27baa2b] First Commit 1 file changed, 1 insertion(+) create mode 100644 hello_world.txt
  3. # ίϛοτޙͷϝοηʔδ [master (root-commit) 27baa2b] First Commit ~~~~~~~ 1 file

    changed, 1 insertion(+) create mode 100644 hello_world.txt # .gitҎԼͷϑΝΠϧ .git/objects/27/baa2b9da21b4485966c2a97268876b189331e9 ~~~~~~~~ SHA-1͕Ұக͍ͯ͠Δ
  4. ͜͜·Ͱͷ·ͱΊ git ͸ • 3छྨͷλΠϓͷΦϒδΣΫτͰ؅ཧͯ͠Δ • commmit • tree •

    blob • ֤ΦϒδΣΫτ͸SHA-1Ͱ؅ཧ͞Ε͍ͯͯΦϒδΣΫτಉ࢜Λ ࢀর͍ͯ͠Δ
  5. ࣍ʹ # ϑΝΠϧΛαϒσΟϨΫτϦʹίϐʔ $ mkdir subdir $ cp hello_world.txt subdir/sample.txt

    $ git add subdir/sample.txt # ݩϑΝΠϧΛॻ͖׵͑ $ echo 'Hello world!!' > hello_world.txt $ git add -u hello_world.txt $ git commit -m'update'
  6. commitͷத਎ $ git cat-file -p HEAD tree 95aaf923a1c8171c9ec05225a3911a0dbeb53d6f parent 27baa2b9da21b4485966c2a97268876b189331e9

    author chiastolite <[email protected]> 1494611946 +0900 committer chiastolite <[email protected]> 1494611946 +0900 update • parent͕௥Ճ͞Ε͍ͯΔ • 1ͭલͷcommitͷSHA-1
  7. treeͷத਎ git cat-file -p 95aaf923a1c8171c9ec05225a3911a0dbeb53d6f 100644 blob b297683f36d0557a8ef83506beda7b80e233723d hello_world.txt 040000

    tree 601df7ed8aabbd875614ba3a301fe344e5c45ae2 subdir • த਎͕มΘͬͨhello_world.txtͷSHA-1͕มԽ • treeͷதʹtree͕
  8. SHA-1ͷ͖·Γ͔ͨ • த਎(+ΦϒδΣΫτͷtype)͔Β Ұҙʹ ܾ·͍ͬͯΔ • ͩΕ͕ͲͷλΠϛϯάͰHello world!ͯ͠΋SHA-1͸ cd0875583aabe89ee197ea133980a9085d08e497 $

    git hash-object -t blob <(echo 'Hello world!') cd0875583aabe89ee197ea133980a9085d08e497 ৄ͘͠͸ Git͸sha1ͷܭࢉΛͲͷΑ͏ʹ΍͍ͬͯΔͷ͔ · DQNEO ىۀ೔ه ͕ৄ͍͠
  9. branch $ git branch test_branch $ cat .git/refs/heads/test_branch 2e7a843cd5706b128e13f06cf7572cda27afa0a7 •

    ϒϥϯνΛ੾͚ͬͨͩͩͱSHA-1͸͔ΘΒͳ͍ • ͜ͷ࣌఺Ͱ͸masterͱԿ΋ҧ͍͕ͳ͍ • ϒϥϯν͸ͲͪΒ͔ͱ͍͏ͱϙΠϯλʔ΍ϥϕϧతײ֮ • ݴ͏΄ͲࢬΆ͘͸ͳ͍
  10. branchΛࢀর͍ͯ͠Δঢ়ଶͰίϛοτΛͯ͠ΈΔ $ git checkout test_branch Switched to branch 'test_branch' $

    git rm -r subdir rm 'subdir/sample.txt' $ git commit -m'Remove sub dir'
  11. $ cat .git/refs/heads/test_branch 508b59bff7ae9af5b516d873eea32c9446540c09 $ git cat-file -p 686bcfe77bf1c43eb8d4e2aa75075e6d6e7e961e tree

    19e6ae1b6538047780cd1d44a10fdb0685f15705 parent 2e7a843cd5706b128e13f06cf7572cda27afa0a7 author chiastolite <[email protected]> 1494613438 +0900 committer chiastolite <[email protected]> 1494613438 +0900 Remove sub dir ίϛοτ͢Δref͕มߋ͞ΕΔ
  12. mergeͯ͠ΈΔ $ git checkout test_branch $ git merge test_branch --no-ff

    Removing subdir/sample.txt Merge made by the 'recursive' strategy. subdir/sample.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 subdir/sample.txt
  13. $ git cat-file -p master tree 19e6ae1b6538047780cd1d44a10fdb0685f15705 parent 2e7a843cd5706b128e13f06cf7572cda27afa0a7 parent

    508b59bff7ae9af5b516d873eea32c9446540c09 author chiastolite <[email protected]> 1494613595 +0900 committer chiastolite <[email protected]> 1494613595 +0900 Merge branch 'test_branch' • parent͕2ͭ • masterͩͬͨͱ͜Ζ • test_branch
  14. $ git rebase master First, rewinding head to replay your

    work on top of it... Applying: Remove sub dir $ cat .git/refs/heads/test_branch 0957492b728dbf7854f46c30be6670fcf29b61a6 ৽͍͠SHA-1
  15. rebaseલͷίϛοτ͸? $ git log 508b59bff7ae9af5b516d873eea32c9446540c09 commit 508b59bff7ae9af5b516d873eea32c9446540c09 Author: chiastolite <[email protected]>

    Date: Sat May 13 03:23:58 2017 +0900 Remove sub dir ී௨ʹΞΫηεͰ͖Δ rebaseͯ͠΋ίϛοτ͕ফ͑ͨΓ͸͠ͳ͍
  16. origin/masterͱorigin masterͷҧ͍ • origin master • originʹઃఆͨ͠ϦϞʔτϦϙδτϦͷmasterϒϥϯν • ϦϞʔτͷ࿩ •

    origin/master • originʹઃఆͨ͠ϦϞʔτϦϙδτϦͷmasterϒϥϯνͷref Λखݩʹίϐʔͨ͠΋ͷ • ϩʔΧϧͷ࿩
  17. Α͘࢖͏Φϓγϣϯ • stash • --keep-index • push • --force-with-lease •

    rebase • -i • --autosquash(git commit --fixupલఏ)
  18. Conditional configuration(>= Git 2.13) $ cat ~/.gitconfig [includeIf "gitdir:~/work/"] path

    = .gitconfig-work [includeIf "gitdir:~/play/"] path = .gitconfig-play $ cat ~/.gitconfig-work [user] name = Hiroyuki Morita email = [email protected] $ cat ~/.gitconfig-play [user] name = chiastolite email = [email protected] ࢓ࣄͱϓϥΠϕʔτɺ࢓ࣄͱOSSͷઃఆΛ෼͚ΒΕΔ