Demystifying Git

Demystifying Git

7ae2c5cad3f71b75706b118c3d06c7b2?s=128

Paulo Ancheta

April 24, 2018
Tweet

Transcript

  1. Helvetica

  2. Demystifying Git

  3. @pauloancheta

  4. None
  5. None
  6. None
  7. None
  8. Gili Trawangan, Indonesia

  9. Demystifying Git

  10. What is Git?! Git is a version control system for

    tracking changes in computer files and coordinating work on those files among multiple people. It is primarily used for source code management in software development, but it can be used to keep track of changes in any set of files. As a distributed revision control system it is aimed at speed, data integrity, and support for distributed, non-linear workflows.
  11. None
  12. What is Git?! • Random three-letter combination that is pronounceable,

    and not actually used by any common UNIX command. The fact that it is a mispronunciation of "get" may or may not be relevant. • stupid. contemptible and despicable. simple. Take your pick from the dictionary of slang. • "global information tracker": you're in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room. • "goddamn idiotic truckload of sh*t": when it breaks
  13. Lego

  14. None
  15. Lego • Consists of small pieces • Each pieces are

    extensible • Easily torn apart • It has pins and connectors so they can be attached to a different piece
  16. Git Objects

  17. Git Object Type • none • Blob • Tree •

    Commit • Tag https://github.com/git/git/blob/master/object.c#L21-L27
  18. Git Object Type: Blob

  19. Git Object Type: Blob $ echo “hello world” | git

    hash-object -w --stdin 3b18e512dba79e4c8300dd08aeb37f8e728b8dad $ cd .git && tree ├── objects │ ├── 3b │ │ └── 18e512dba79e4c8300dd08aeb37f8e728b8dad │ ├── info │ └── pack
  20. Git Object Type: Blob $ git cat-file -s 3b18e512dba79e4c8300dd08aeb37f8e728b8dad 12

    $ git cat-file -t 3b18e512dba79e4c8300dd08aeb37f8e728b8dad blob $ git cat-file -p 3b18e512dba79e4c8300dd08aeb37f8e728b8dad hello world
  21. Git Object Type: Blob $ git update-index --add --cache-info 100644

    3b18e512dba79e4c8300dd08aeb37f8e728b8dad hello.txt $ git status Changes to be committed: new file: hello.txt Changes not staged for commit: deleted: hello.txt
  22. Git Object Type: Blob $ echo “hello world” > hello.txt

    $ git status Untracked files: (use "git add <file>..." to include in what will be committed) hello.txt
  23. Git Object Type: Tree

  24. Git Object Type: Tree $ git write-tree 68aba62e560c0ebc3396e8ae9335232cd93a3f60 $ git

    cat-file -t 68aba62e560c0ebc3396e8ae9335232cd93a3f60 Tree $ git cat-file -p 68aba62e560c0ebc3396e8ae9335232cd93a3f60 100644 blob 3b18e512dba79e4c8300dd08aeb37f8e728b8dad hello.txt
  25. Git Object Type: Commit

  26. Git Commit • Author • Date • Tree • SHA

    • Commit message https://github.com/git/git/blob/master/commit.c#L1306-L1310
  27. Git Object Type: Commit $ git commit-tree 68aba62e560c0ebc3396e8ae9335232cd93a3f60 -m “My

    Initial Commit” $ git log fatal: your current branch 'master' does not have any commits yet
  28. Git HEAD

  29. None
  30. ae3aedc Initial commit f54f95f I guess it works now, but

    I have no idea why 8308941 Changes because John said so f3a1c80 Fix failures because of John’s comment eb0d8ef ZOMG please don’t ask me
  31. Git Object Type: Commit $ cat .git/HEAD ref: refs/heads/master $

    find .git/refs refs refs/heads refs/tags
  32. Git Object Type: Commit $ git update-ref refs/heads/master bb429db985800c23d0b1773e844e846af8ab5fe7 $

    git log Commit bb429db985800c23d0b1773e844e846af8ab5fe7 My Initial Commit
  33. We made our first commit!

  34. Demystifying Git Using Ruby

  35. FakeGit gem install fake_git

  36. FakeGit: Init $ fakegit init $ fakegit init my-repo

  37. FakeGit: Handling Executable ./exe/fakegit* Handle no stdin ------------> With stdin

    ----------------->
  38. FakeGit: Handling Executable ZOMG IS THAT A GLOBAL? ------>

  39. FakeGit: Handling Different Commands Constantize ---->

  40. FakeGit: Init $ fakegit init $ fakegit init my-repo

  41. FakeGit: hash-object Obj can write To storage -------------->

  42. FakeGit: priv/object Just an initialize --------> Raise on type error

    -------> Other write methods are Private ------------------->
  43. OG Git: db storage Original git /objects/\w\w/\w*/

  44. FakeGit: db storage .fakegit/objects/\w\w/\w*/ Comma separated values. key=value format

  45. FakeGit: fetch-object Build a new object from File -------------------->

  46. FakeGit: list-objects

  47. FakeGit: update-index

  48. FakeGit: Log

  49. Magic

  50. Sources Advanced Git Tutorial • https://www.youtube.com/watch?v=0SJCYPsef54 Git Repository • https://github.com/git/git

    Git Internals - Git References • https://git-scm.com/book/en/v2/Git-Internals-Git-Referenc es Git Internals - Git Objects • https://git-scm.com/book/en/v2/Git-Internals-Git-Objects StackOverflow git HEAD(~ vs ^ vs @{}) • https://stackoverflow.com/questions/26785118/head-vs-he ad-vs-head-also-known-as-tilde-vs-caret-vs-at-sign/267852 00
  51. @pauloancheta Thank You!