7 ms·
Some Git internals
- strogonoff 6y agoNice walkthrough! I did not know about FETCH_HEAD. Another (complementing) way of getting an idea how Git works is by reading the source of Isomorphic Git[0]. Being in JS and with fewer (as of now) features, it’s a bit more accessible than reference Git. [0] E.g. https://github.com/isomorphic-git/isomorphic-git/blob/main/src/storage/readObject.js https://github.com/isomorphic-git/isomorphic-git/blob/main/s...
- duffmancd 6y agoI really enjoyed running through Write Yourself A Git[0], which guides you through implementing a basic Git replacement in python. [0]https://wyag.thb.lt/ https://wyag.thb.lt/
- Waterluvian 6y agoThis was really really educational. Git internals seem rather simple. Does anyone have a really good visual explanation of what's being done to the tree and such when commits and merges and rebases are done? I still don't quite grok it intimately enough.
- rustybolt 6y agolearngitbranching.js.org is quite good
- divbzero 6y agoThe Git Internals section of the Pro Git book covers commits [1] and branches [2] well though it doesn’t go into details about merges and rebases. [1]: https://git-scm.com/book/en/v2/Git-Internals-Git-Objects https://git-scm.com/book/en/v2/Git-Internals-Git-Objects [2]: https://git-scm.com/book/en/v2/Git-Internals-Git-References https://git-scm.com/book/en/v2/Git-Internals-Git-References
- edrobap 6y agoBranching is more of an art. With the kind of flexibility git provides, one can get lost in the convention to follow. I have found this useful For a small team working on app development - https://nvie.com/posts/a-successful-git-branching-model/ https://nvie.com/posts/a-successful-git-branching-model/
- aequitas 6y agoUngit[0] shows what will happen to the tree before you execute a merge or rebase. It really helped me get a hang of Git. [0] https://github.com/FredrikNoren/ungit https://github.com/FredrikNoren/ungit
- sransara 6y agoI wrote my self a note about this last year to demystify the internal data structure [0], if you want to check it out. But the TLDR straight to rabbit holes; is that commits are a directed acyclic graph (DAG) [1]. And the file tree snapshot is a fully persistent trie [2]. And the commit DAG points to different snapshots. Branches are name shortcuts to commits. [0] https://sransara.com/notes/2019/build-yourself-a-git/ https://sransara.com/notes/2019/build-yourself-a-git/ [1] https://en.wikipedia.org/wiki/Directed_acyclic_graph https://en.wikipedia.org/wiki/Directed_acyclic_graph [2] https://en.wikipedia.org/wiki/Persistent_data_structure https://en.wikipedia.org/wiki/Persistent_data_structure
- ufo 6y agoA dumb question: if I make a commit changing just a single line in a large file, does this create a completely new object/blob with the entire contents of the file? Or does it store it in a more space-efficient manner?
- glandium 6y agoThe former, until you run git gc, in which case the latter happens.
- ufo 6y agoWow! Running git gc just shrunk my .git folder from 18MB to only 3MB.
- sitzkrieg 6y agodid it have binary data? if so try moving to lfs and running bfg cleaner and watch it shrink even more
- glandium 6y agogit gc runs automatically when some threshold is met in the number of "loose" objects (objects that were created by e.g. git add and that haven't been packed yet). I don't remember what the threshold is, though.
- 6y ago
- shadykiller 6y agoGit is really simple at the core and fun to poke around with. I gave a talk in RubyConf India about poking with git internals using ruby. It was fun. Link for anyone interested(not very high quality but watchable): https://www.youtube.com/watch?v=lPlwkxrG2NM https://www.youtube.com/watch?v=lPlwkxrG2NM
- srathi 6y agoGood intro. Shameless plug: I recently picked up Golang and used it to implement a mini version of Git CLI using these internals [1]. [1] https://github.com/ssrathi/gogit https://github.com/ssrathi/gogit
- deleted 6y ago[deleted]
- aarchi 6y agoA FUSE filesystem that fetches objects on demand seems like it would be great when working in a large repo such as the Linux Kernel or Chromium, especially when only a small subset of files are needed. It would also be useful to monitor the fs for file changes since `git status` scans the entire tree. Does anything like this exist?
- arunc 6y agoThe website looks terrible on Opera on Android.