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

So Help Me God, You Will Understand Git's Model, Even If It Kills Me

So Help Me God, You Will Understand Git's Model, Even If It Kills Me

Scott Robinson

April 25, 2012
Tweet

More Decks by Scott Robinson

Other Decks in Programming

Transcript

  1. Go drink.
    Presentation starts at
    6pm.

    View Slide

  2. 1
    2 3
    4
    6
    7 8
    9 11 15 16
    10 12 14
    5 13
    Trunk
    Branches
    Merges
    Tags
    Discontinued
    development branch

    View Slide

  3. Everyone Has A Fork
    • Offline
    • No server necessary
    • Frequent branching and merging

    View Slide

  4. View Slide

  5. So Help Me God,
    You Will Understand Git’s
    Model
    Even If It Kills Me

    View Slide

  6. SHA1
    $ echo 'HELLO TWU' | shasum
    7068de75a45caca38a6d772d4b0f371bda003256 -

    View Slide

  7. Git Object Model
    •K: SHA(data)
    •V: data

    View Slide

  8. Objects
    •Type
    •Size
    •Content

    View Slide

  9. Blobs
    Trees
    Commits
    Refs
    Tags

    View Slide

  10. Blobs
    $ git cat-file -p 1377554ebea6f98a2c748183bc5a96852af12ac2
    *.swp

    View Slide

  11. Trees
    $ git ls-tree eebc19d60284277eba86620ec828d73d0cdf822a
    100644 blob 1377554ebea6f98a2c748183bc5a96852af12ac2 .gitignore
    100644 blob ac1bfdc65a699792310498fc0ba003e61eddf1d0 bad.lua
    100644 blob b2f5ce962808f4edd04336eb803b6445b843e052 boom.lua
    100644 blob 6b1c0b8946e40ff393f73d80a885fdd39fba93dd bullet.lua
    100644 blob 268a04ca259b566c7340d8ba8dab8ce0590e8352 main.lua
    100644 blob 67638336f18030013b0bcc7533987a6ba892ba46 rail.lua
    040000 tree 415ee50b6cf27815df2750de33b0eac1df8ad814 resources
    100644 blob c1a79a49a98c0b3868e33270465121cf40dc622e ship.lua
    100644 blob d77c7f1d5fecfc6c998e2eec628495075ba27ec1 wave.lua

    View Slide

  12. Commit
    •Tree
    •Parent(s)
    •Author and Committer
    •Message

    View Slide

  13. Commit
    $ git cat-file -p eea6bd6db666365b33496b9fc4c2d55c7af8fdcd
    tree eebc19d60284277eba86620ec828d73d0cdf822a
    parent bfe1204bb4d8eaa00b7a20c47e6e421e9be25322
    author Sam Gibson 1327417487 +0530
    committer Sam Gibson 1327417487 +0530
    Bounds -> Box

    View Slide

  14. Tags
    •Annotated
    •Lightweight

    View Slide

  15. Annotated Tag
    •Object SHA1
    •Type
    •Tagger
    •Message

    View Slide

  16. Refs
    (lightweight tags)
    •Branches (local and remote)
    •Heads
    •Tags

    View Slide

  17. INCOMING
    COPYRIGHT
    VIOLATION

    View Slide

  18. In Summary
    http://book.git-scm.com/1_the_git_object_model.html

    View Slide

  19. Let’s Play A Game
    “What Happens?”

    View Slide

  20. What Happens?
    $ git init
    Initialized empty Git repository in /.git/

    View Slide

  21. Yes, that was a warm up
    $ find ./.git
    .
    ./.git
    ./.git/config
    ./.git/description
    ./.git/HEAD
    ./.git/hooks
    ...
    ./.git/info/exclude
    ./.git/objects/info
    ./.git/objects/pack
    ./.git/refs/heads
    ./.git/refs/tags

    View Slide

  22. What Happens?
    $ touch xyzzy
    $ git add xyzzy
    $ git status
    # On branch master
    #
    # Initial commit
    #
    # Changes to be committed:
    # (use "git rm --cached ..." to unstage)
    #
    # new file: xyzzy
    #

    View Slide

  23. The Index
    •Cache
    •Staging
    •Whitelist?!

    View Slide

  24. You Delete A File And
    Then Commit It?
    $ rm xyzzy
    $ git commit -m 'What happens?'

    View Slide

  25. You Can’t Explain That!
    $ ls
    $ git status
    # On branch master
    # Changes not staged for commit:
    # (use "git add/rm ..." to update what will be committed)
    # (use "git checkout -- ..." to discard changes in
    working directory)
    #
    # deleted: xyzzy
    #
    no changes added to commit (use "git add" and/or "git commit -a")
    $ git checkout -- xyzzy
    $ ls
    xyzzy

    View Slide

  26. Reflogs
    $ git reflog
    add17aa [email protected]{0}: commit: NO
    a1b7f8d [email protected]{1}: commit (initial): What happens?

    View Slide

  27. Practical Examples
    whereupon mayhap we conversate

    View Slide

  28. Fetch
    Imports remote refs
    and their associated objects

    View Slide

  29. 3-Way Merge
    • "your" commit
    • "their" commit
    • their most recent ancestor

    View Slide

  30. Rebase
    • "your" commit
    • "their" base commit
    • their most recent ancestor
    • Replays each of “your” differences
    upon “their” base

    View Slide

  31. Stash Working
    Directory
    Index
    HEAD

    View Slide

  32. fin

    View Slide

  33. Git Community Book
    http://book.git-scm.com

    View Slide