9 ms·
In a Git repository, where do your files live?
- p4bl0 3y agoThanks for sharing this very interesting link (I actually knew it would be good before clicking simply because of the domain name)! If this sort of internal view of git interests you, I strongly suggest reading the "DIY Git in Python" series from here: https://www.leshenko.net/p/ugit/ https://www.leshenko.net/p/ugit/
- js2 3y agoI realize the Python script is likely provided for didactic purposes, but you can use `git hash-object` to get the object ID: https://git-scm.com/docs/git-hash-object https://git-scm.com/docs/git-hash-object With a bit of sed, the python script in the blog post becomes: git hash-object <path> | sed -E 's|(..)(.*)|.git/objects/\1/\2|' The inverse of `git hash-object` is `git cat-file`: git cat-file -p $(git hash-object <path>) https://git-scm.com/docs/git-cat-file https://git-scm.com/docs/git-cat-file Aside, when I learn a new subject, I like to go to the index such that it is to get an idea of what I don't know (first stage of learning: you don't know what you don't know). Then I can try to prioritize the order of learning about the topic. With git, I'd start with this page: https://git-scm.com/docs/git https://git-scm.com/docs/git
- drewg123 3y agoI have a local clone of a git repo with many local branches. I lost an object file (and I'm not certain how). Now git gc always fails, complaining about the object: Counting objects: 100% (11785289/11785289), done. Delta compression using up to 64 threads Compressing objects: 100% (4116944/4116944), done. fatal: unable to read 1cae71a9d5b24991c0d632b45186ca8a250e5d52 fatal: failed to run repack I've cloned the repo again, and that object does not appear in the new clone, so I assume it must be from a commit to a local branch. The odd thing is that I think I locally cloned this repo, and saw no complaints about the missing object. Is there any way to tell what branch and/or file(s) were referred to by the object? And, assuming its from a stale branch, just delete the branch and thereby fix my repo?
- masklinn 3y agoYou can try to git fsck in case that identifies the missing object. But I’m not sure there’s any ready made command to identify through which path a missing object is reached. It could actually be the reflog. Pruning the reflog then running “git gc —prune=now” might do the trick.
- drewg123 3y agoThank you. I've tried git fsck in the past, and it complains about the missing object as well. And I just tried "git gc —prune=now", and sadly it still fails the same way. I'm afraid I'm going to have to bite the bullet and clean up my 30 or so worktrees and re-clone the repo, and re-create the worktrees.
- williamcotton 3y agoTry a grep for that missing hash in the fatal message you posted and point it at a commit/object that does exist or just delete that line/file and see if that fixes it!
- drewg123 3y agoThis is more or less what I've been trying to do for quite a while. How do I grep for it? And once I do that, how can I "point it at a commit/object that does exist ?"
- williamcotton 3y agoIf it's a ref somewhere then it'll just be a string of the hash deadbeef style. Just open the file up and change it to another commit hash or just delete the ref completely. Try something like: grep -r "1cae71a9" ./.git/ And see if it comes up somewhere. My guess is that it's a ref for some old branch pointing at a commit that isn't around.
- 3y ago
- smartmic 3y agoOh yeah, the Git internals... I tried to find my way through them using visualization but did not progress much: https://github.com/smartmic/git2pic https://github.com/smartmic/git2pic
- metaltyphoon 3y agoThis was my aha! Momment https://youtu.be/P6jD966jzlk?si=YNKrNf872IQqr1vj https://youtu.be/P6jD966jzlk?si=YNKrNf872IQqr1vj
- gjf 3y agoI tried to do something similar: https://articles.foletta.org/post/git-under-the-hood/ https://articles.foletta.org/post/git-under-the-hood/
- sillysaurusx 3y agoI encourage everyone to read A Plumber's Guide to Git: https://alexwlchan.net/a-plumbers-guide-to-git/ https://alexwlchan.net/a-plumbers-guide-to-git/ It's not a book, just a series of five short blog posts. Part 1 explains precisely where files live: https://alexwlchan.net/a-plumbers-guide-to-git/1-the-git-object-store/ https://alexwlchan.net/a-plumbers-guide-to-git/1-the-git-obj... $ mkdir animals $ cd animals $ git init $ echo "Big blue basilisks bawl in the basement" > animals.txt $ git hash-object -w animals.txt b13311e04762c322493e8562e6ce145a899ce570 $ find .git/objects -type f .git/objects/b1/3311e04762c322493e8562e6ce145a899ce570 $ rm animals.txt $ git cat-file -p b13311e04762c322493e8562e6ce145a899ce570 > animals.txt Congratulations, you just did a `git restore animals.txt` manually. Parts 2 through 5 are equally illuminating.
- bloopernova 3y agoThank you a thousand times for sharing that. I just ran through the examples and they were very enlightening.
- srathi 3y agoIt is fun to explore the Git internals! Some time back, I used it to learn Golang [1]. Two birds with one stone! [1] https://github.com/ssrathi/gogit https://github.com/ssrathi/gogit
- globular-toast 3y agoYou don't need to know this, by the way. You can totally just think of git as simply storing a copy of your entire repo every time you make a commit. This is one part of git that actually is a good abstraction. Of course it is fun to know this but it won't help you understand git really, and please don't tell people who are just learning git. Just say git makes a copy of the whole project every time you commit.
- recursive 3y ago"I don't commit that often because I don't have that much hard drive space."
- jxy 3y agoIt's kind of true with git-lfs.
- mostlylurks 3y agoI wonder if anyone has built a system with the philosophy of the opposite extreme. "Oh yeah, space is cheap, so I just let my automated system make 10,000 commits per second. It'll be fine."
- quickthrower2 3y agoI have been thinking about this. Why no record all keystrokes. Then checkpoint where you are whenever you desire. These days AI could describe any arbitrary span of code changes.
- mikewarot 3y ago>Why not record all keystrokes? That was Google Wave, it stored everything as an "operational transform". The presentation they used when showing it off to the world was brain damaged, they insisted as showing it off as a ton of separate blocks, instead of one continuous document, which gave people the wrong impression of it, and tanked it. In a similar way, the impression that Git stores deltas, got stuck in my head somehow at the beginning and made it an opaque mystery for me. It was only years later, when I somehow I managed to learn the truth, that Git stores full snapshots, and except for compression in extreme cases to save storage, it doesn't do anything with deltas (except fake them to show diffs)
- bloopernova 3y agoVery apropos, I'm trying to write a guide for my team called "git beyond pull/push and checkout". I'm trying to write something that will demystify git for the developers in this team. So I want to show them the files in .git, and connect them to the concepts they know like branches, etc. I'm always on the lookout for new stuff to include. The more I can read, the better information I can put in this guide.
- grahamplace 3y agoI’d definitely read this if you’re able to share it publicly
- bloopernova 3y agoI'll probably announce it on HN when it's finished :)
- tcoff91 3y agoYou should read this: https://jwiegley.github.io/git-from-the-bottom-up/ https://jwiegley.github.io/git-from-the-bottom-up/
- Vinnl 3y agoHeh, "git beyond pull/push and checkout" was also the idea behind my tutorial, though I figured visualising the commit graph would be more helpful than showing the hidden files. And also that a ~10 min guide would be more likely to be used than a very detailed book. Anyway, in case you're interested: https://agripongit.vincenttunru.com https://agripongit.vincenttunru.com
- deepspace 3y agoThat was very informative, but I wondered if there is an easy-to-read reference somewhere about WHY git works the way it does? I am old enough to have used SCCS, RCS and CVS extensively. Each had their faults, but Git is the only VCS I have used where dealing with merge conflicts is unintuitive enough that I sometimes end up with the repository in an unusable state. I am sure I am doing something wrong, but I would like to understand why. The VCS that maps closes to the way my brain works is ClearCase. You essentially have a versioned file system, and you can set up a view to present any previous state of that file system. Of course, administration is a nightmare, it is not distributed, it is expensive, yada, yada. But when using it I always felt I knew exactly what was going on under the covers, which is not the case with Git at all.
- zadokshi 3y agoI used git for years now. I’m comfortable with all of the basic functions. It is my experience that I have had several times where merging/branching has caused a repo to “break” It doesn’t happen often, but when it does it’s super frustrating and this I avoid the merging workflows where possible. I’m sure if I educate myself a bit more about git and pay more careful attention to the details, I wouldn’t occasionally have this problem, but Git really shouldn’t be like this.
- jayshua 3y agoWhat does a broken repo look like? What does broken mean here?
- appplication 3y agoGit could be a lot better in a lot of ways, particularly from a developer experience perspective. I’m a little surprised we haven’t seen a meaningful successor. One example is how git will deceive you and tell you you’re up to date with your remote (e.g. origin/main). What it means is that your local branch is up to date with its local concept of remote, and makes no statement guarantees about the actual state of the remote. Which is really a nonsense concept that does not need to exist. Similarly the whole concept of needing to specify “origin” at all is a bit bonkers and does no favors. Why is it that I can pull from a remote branch, commit some changes, run ‘git push’ and git has no idea what branch I want to push to. Another example: if main is a protected branch, don’t let me accidentally commit to it locally. I could keep going with the examples but I won’t. And yeah you can forgive all this by quibbling that git was written in a time when internet access was not ubiquitous, and of course all these decisions make sense because x, y, or z advanced edge case for advanced users only, and I’m a shitty engineer because all of this complexity secretly makes my life better and I’m just too simpleminded to appreciate it. Really though, if you rewrote git from a principles first approach (with developer experience being one of those principles), it certainly would not look like how it looks today. There is too much complexity, too many ways to do things, and too many bad decisions around defaults. Treat it like a proper distributed system, perhaps even backed by a real database. It’s not special because the data is code. The fact that it’s treated as such is the reason it feels so weird.
- temeya 3y agoWhile I've used Git a bit, and appreciate for what it is, I will admit that it's syntax is what makes it a bit difficult. If the Git commands had kept to a single metaphor, then I think that would have helped tremendously. Even now, I'm still trying to figure out the best metaphor for using Git and it's commands. So far the closest I have is a tree metaphor as follows: Git init = tree planted Git add and Git merge = trunk grows Git branch = branch grows Git merge = branch intersects And so on. But even this falls apart once I get to Git diff and Git checkout.
- brainbag 3y agoIf you haven't watched the brilliant Git For Ages 4 and Up I can't recommend it more highly. I make everyone watch it on my teams and my students. https://m.youtube.com/watch?v=3m7BgIvC-uQ https://m.youtube.com/watch?v=3m7BgIvC-uQ Git is quite simple under the hood, it's the convoluted user interface that makes it seem so difficult. Once you understand technically what the commands are doing, it's a lot easier to know which one to reach for.
- deleted 3y ago[deleted]
- deleted 3y ago[deleted]
- valty 3y agoGit has biggest moat of all software, and it is stifling innovation. On one side it's good because everyone is using the same tool and we don't have to learn many different intricacies of other tools. But on the other side, there's probably a better way of doing things that could dramatically simplify everything. It was designed so long ago with such different computing and memory constraints, and the way we use repos today is very different - think monorepos. There are so many projects trying to bandaid solutions to its scaling issues, and so many projects are using monorepos today which are not well supported. I genuinely believe re-writing a VCS is actually a very simple task. If you look at the core use cases, or the commands people use, they are very few.
- offices 3y agoDiscussions on improving git tend to be dominated by people who not only don't grok git but don't actually grok the problems inherent with distributed code development and want it to be little more than dropbox for github. Once you filter out these people, a good chunk of the remainders are people asking for UI changes that already exist but they didn't bother to learn. Catering to these people means attempts at this problem usually punish power users by removing useful things like staging or a distinction between commit and push.
- valty 3y ago> Discussions on improving git I'm advocating for a replacement...and why it's so difficult. > distributed code development Code development is no longer distributed. It's centralized in Github/Gitlab for about 99% of cases. And everyone is always connected in real-time to a central server...and also to all other contributors. These possibilities are so far from the reality of when Git was created. > staging or a distinction between commit and push This is trivial to handle.
- yencabulator 3y agoEven outside of the distributed aspect, discussions on improving git tend to be started by people who have never felt the need to express `HEAD~10` or `origin/main...main`, and.. I just don't have much sympathy for the naivety left in me. It would be neat to have a GUI rebase -i style "commit reorganizer" that let you visually reorder & drag commits between branches etc. But that'd just be an app calling git, and once you're experienced enough write it, you no longer really need it. So nobody does.
- x86x87 3y agohttps://git-scm.com/book/en/v2 https://git-scm.com/book/en/v2 Git internals chapter. You'll learn more than you ever wanted to know about how git works. Plus this classic: https://tom.preston-werner.com/2009/05/19/the-git-parable.html https://tom.preston-werner.com/2009/05/19/the-git-parable.ht...