[HN Gopher] In a Git repository, where do your files live? ___________________________________________________________________ In a Git repository, where do your files live? Author : todsacerdoti Score : 132 points Date : 2023-09-14 18:34 UTC (4 hours ago) (HTM) web link (jvns.ca) (TXT) w3m dump (jvns.ca) | p4bl0 wrote: | Thanks 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/ | js2 wrote: | I 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 | | 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 | | 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 | drewg123 wrote: | I 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 wrote: | You 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 wrote: | Thank 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 wrote: | Try 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 wrote: | This 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 ?" | pcthrowaway wrote: | You might be able to recreate the git history without | that object (or commit). Look into commands like filter- | branch. I'd be surprised if there's not a way to recover | from this situation | bloopernova wrote: | Very 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 wrote: | I'd definitely read this if you're able to share it publicly | bloopernova wrote: | I'll probably announce it on HN when it's finished :) | tcoff91 wrote: | You should read this: https://jwiegley.github.io/git-from- | the-bottom-up/ | globular-toast wrote: | You 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. | glhaynes wrote: | I feel like git culture is one of the worst about these sorts | of things. I've run into people that think you're a loser if | you don't use it from the command line, but my commits using a | GUI client are much cleaner and I seem to have much less | trouble than they do. | recursive wrote: | "I don't commit that often because I don't have that much hard | drive space." | mostlylurks wrote: | I 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." | jxy wrote: | It's kind of true with git-lfs. | smartmic wrote: | Oh yeah, the Git internals... I tried to find my way through them | using visualization but did not progress much: | https://github.com/smartmic/git2pic | srathi wrote: | It 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 | metaltyphoon wrote: | This was my aha! Momment | https://youtu.be/P6jD966jzlk?si=YNKrNf872IQqr1vj | gjf wrote: | I tried to do something similar: | https://articles.foletta.org/post/git-under-the-hood/ | sillysaurusx wrote: | I encourage everyone to read A Plumber's 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-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. | deepspace wrote: | That 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 wrote: | I 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 wrote: | What does a broken repo look like? What does broken mean | here? ___________________________________________________________________ (page generated 2023-09-14 23:00 UTC)