Dive into .git

1,307 views

Published on

This slide was made for 10 minutes demo. in a tech meeting of my company.

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,307
On SlideShare
0
From Embeds
0
Number of Embeds
14
Actions
Shares
0
Downloads
3
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Dive into .git

  1. 1. Dive into .git 2012-05-24 Dr. NISHIO Hirokazuhttp://www.nishiohirokazu.org/
  2. 2. about• This slide was made for 10 minutes demo. in a tech meeting of my company.• When you print it, put 16 slides per a page will be good enough.• This slide was published under CC-BY 3.0 License. You don’t need my permission to share it.
  3. 3. “Git is difficult!”• “A lot of difficult concepts!”• OK, put aside those concepts and look actually what is going on with Git!• I hope this demonstration helps you draw picture of Git in your mind.
  4. 4. Make a repository$ mkdir test No tricks, no gimmicks!$ cd test Just an empty directory.$ ls -a. ..$ git initInitialized empty Git repositoryin .../test/.git/ ←You got it! “$ git init test” works same
  5. 5. $ ls -a. .. .git Here is your repository!
  6. 6. Let’s look into it!$ cd .git$ tree.|-- HEAD|-- config|-- description|-- hooks|-- info| `-- exclude|-- objects| |-- info| `-- pack`-- refs |-- heads `-- tags (hooks is omitted)
  7. 7. What is changed when you committed?$ cd ..$ touch README$ git add README$ git commit -m “initial commit”[master (root-commit) 4dd66d3]initial commit
  8. 8. You got 3 objects!$ tree .git/objects.git/objects|-- 4d| `-- d66d3a32a66f3578317717ccfb18|-- 54| `-- 3b9bebdc6bd5c4b22136034a95dd|-- e6| `-- 9de29bb2d1d6434b8b29ae775ad8|-- info`-- pack Last of filename is omitted. Some changes outside of objects are omitted
  9. 9. Look into the objects! Make show.py:$ cat > show.py#!/usr/bin/env pythonimport sysimport zlibdata = file(sys.argv[1], "rb").read()data = zlib.decompress(data)print repr(data) Don’t forget chmod +x
  10. 10. In commit obj$ ./show.py .git/objects/4d/d6...commit 201x00tree 543b...nauthor NISHIO Hirokazu <...> 1337655529 +0900ncommitter NISHIO Hirokazu <...> 1337655529 +0900nninitial commitn Its filename was shown when you committed. I broke lines for readability. Notice on “tree 543b”
  11. 11. In tree obj$ ./show.py 54/3b...tree 34x00100644 READMEx00xe6x9dxe2x9b... I broke lines. Notice on e69b
  12. 12. In blob obj$ ./show.py e6/9d...blob 0x00 It is content of README. It is empty now, thus size=0 and nothing are after x00
  13. 13. Filename of objects$ python -c “import hashlib;hashlib.sha1(blob 0x00).hexdigest()”e69de29b... It is sha1 hash of its content!
  14. 14. Conclusion• Repository is in .git• There are many objects in .git/objects/• Their contents are compressed with zlib and their filenames are sha1 hash of uncompressed contents.• They are commit obj, tree obj and blob obj.• Today I omitted on tags and refs (next time?)
  15. 15. Let’s try!• Edit README and look changes!• New commit obj has “parent <hash>” line• New blob has new content of README• Add new files and look changes in tree obj• When you add lines on README, does blob have whether diff or total content?
  16. 16. Appendix• Q: Why don’t you use “git show --format=raw”• A: Because it doesn’t show important information.
  17. 17. In tree obj...$ git show --format=raw 543btree 543bREADME Oh, how can I know its contents is in e69d? That’s why I need to make show.py
  18. 18. Appendix• Q: Why don’t you use gunzip to extract it?• A: It is compressed with zlib, however it is now a valid zip-file (it doesn’t have headers)• If you know easier way, please tell me!

×