News for hackers. Stuff that matters.
Re:In a Git repository, where do your files live? by deepspace on Thursday September 14, 2023 @06:41PM (#37515760)
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.

Re:In a Git repository, where do your files live? by zadokshi on Thursday September 14, 2023 @06:47PM (#37515820)
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.
Re:In a Git repository, where do your files live? by jayshua on Thursday September 14, 2023 @06:55PM (#37515904)
What does a broken repo look like? What does broken mean here?
Re:In a Git repository, where do your files live? by appplication on Thursday September 14, 2023 @07:08PM (#37516007)
Git 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.

Re:In a Git repository, where do your files live? by OkayPhysicist on Thursday September 14, 2023 @07:38PM (#37516258)
You're confused because you're treating the repo server as special.

Git doesn't do special. All branches, on all machines, are just branches. "main" on your device and "origin/main" (main on the machine you called "origin"), are two different branches. They don't need to share a name, you can just as easily set your local "main" to have "origin/Release" as its upstream. The name "main" isn't special. You can name your branches anything you desire. If you want to lock yourself out from controlling your own code, that's a customization for you to make. To git, there's no difference between committing to "main","feature111", or anything else. "origin" isn't special, either: you can have many different repo servers hosting different branches. Or maybe you don't have a repo server at all, and you just have all your fellow devs machines and you coordinate via email.

While being perhaps a bit un-opinionated, it also makes Git conceptually extremely consistent, and thus simple.

Re:In a Git repository, where do your files live? by appplication on Thursday September 14, 2023 @08:08PM (#37516507)
I certainly understand the abstraction and how to use git in this sense. The foundation of my above opinion is that I don’t think this is a great idea that’s well applied to modern development.

Is it elegant that the same version control system can be used whether you have a remote server or you just coordinate over email? It certainly is! Is it necessary to have this level of generality and lack of opinions when 95% of users just want to do the same basic flow (and it does involve a server of some kind)? I don’t really think so, which is why I think there is so much confusion around really basic git functionality.

We live in a world where git is philosophically more like Perl than python, and I think that it’s not unreasonable to think that it’s possible that if we flipped that, then that might actually be a good thing.

Re:In a Git repository, where do your files live? by ylyn on Thursday September 14, 2023 @09:16PM (#37516963)
Then write your own wrapper on top of Git.
Re:In a Git repository, where do your files live? by TeeMassive on Thursday September 14, 2023 @10:20PM (#37517471)
Lazy Git ftw
Re:In a Git repository, where do your files live? by TylerE on Thursday September 14, 2023 @07:24PM (#37516141)
Blame the Linus Torvalds personality cult. Only way that terrible UX got traction in the first place. If anyone OTHER than Linus had written it, it would have been mocked, and deservedly so.
Re:In a Git repository, where do your files live? by appplication on Thursday September 14, 2023 @07:38PM (#37516259)
Yeah, I originally had some Linus snark in there but deleted it. My above comment is being rapidly downvoted though, which is in some sense validating.
Re:In a Git repository, where do your files live? by Yodel0914 on Thursday September 14, 2023 @07:52PM (#37516373)
That's a pretty big claim. Git solved real problems at the time in a novel and extremely useful way. Coming from SVN (or god forbid VSS), the power and flexibility of git more than made up for its difficulty to grasp.

Why it "won" over alternatives with cleaner UX (eg Hg) is a different question, and I think has a lot to do with github.

Re:In a Git repository, where do your files live? by spaniard89277 on Thursday September 14, 2023 @08:07PM (#37516497)
Git may solve real problems but honestly, it's a PITA to use. Just for basic tasks needs quite a lot time sink to understand what's going on and what do you need to do.

It gets in the way of the workflow IMO.

Re:In a Git repository, where do your files live? by TylerE on Thursday September 14, 2023 @10:05PM (#37517348)
Mercurial came out essentially simultaneously, solved the same problems, with a much more coherent UX.
Re:In a Git repository, where do your files live? by Yodel0914 on Thursday September 14, 2023 @10:25PM (#37517517)
Early on, I was definitely a proponent for hg over git. I assumed it would at the very least remain a peer, given how much more sane the UX is. I was wrong though, and I don't think it's just because of github.

Named branches being baked in turned out to actually be a real pain in mercurial. Sure, you can use bookmarks (and we did) but starts to quickly feel like you're swimming against the current.

Re:In a Git repository, where do your files live? by KRAKRISMOTT on Thursday September 14, 2023 @08:31PM (#37516655)
It's bigger than him. GitHub built their SaaS on top of it. Had they chosen subversion or fossil, history would be very different.

People use git because everybody else uses git and it started because GitHub provides easy code sharing and a better UI than the alternative — SourceForge and mailing lists.

Re:In a Git repository, where do your files live? by mr_toad on Thursday September 14, 2023 @09:31PM (#37517098)
People could have kept using SVN or whatever else. They jumped ship in droves, way before GitHub.

At the time it was the only distributed and open source VCS. Fossil may have come quickly on its heels, but it was already too late.

Re:In a Git repository, where do your files live? by fragmede on Thursday September 14, 2023 @09:38PM (#37517145)
[delayed]
Re:In a Git repository, where do your files live? by eru on Thursday September 14, 2023 @10:02PM (#37517323)
And others were released before git:

> The first open-source DVCS systems included Arch, Monotone, and Darcs. However, open source DVCSs were never very popular until the release of Git and Mercurial.

https://en.wikipedia.org/wiki/Distributed_version_control#Hi...

Re:In a Git repository, where do your files live? by bloopernova on Thursday September 14, 2023 @07:34PM (#37516229)
Git separates its plumbing from its porcelain very well. That makes all the different front ends possible. Maybe there's one that will help you to work with git?

I differ from your opinion that the user experience is poor. I think it's great, and I prefer using the command line interface.

Re:In a Git repository, where do your files live? by tmacam on Thursday September 14, 2023 @08:13PM (#37516556)
As an example of a different frontend, have you tried "jujutso" [1]? Every time I ended seeing a comment about git vs Hg usability I am reminded of it. It uses git in the backend but its workflow/frontend seems streamlined.

  Jujutsu is a Git-compatible DVCS. It combines features from Git (data model, speed), Mercurial (anonymous branching, simple CLI free from "the index", revsets, powerful history-rewriting), and Pijul/Darcs (first-class conflicts), with features not found in most of them (working-copy-as-a-commit, undo functionality, automatic rebase, safe replication via rsync, Dropbox, or distributed file system).
[1] https://github.com/martinvonz/jj
Re:In a Git repository, where do your files live? by appplication on Friday September 15, 2023 @12:40AM (#37518505)
This is pretty interesting. Maybe a missed opportunity to call it jugitsu
Re:In a Git repository, where do your files live? by zaphirplane on Thursday September 14, 2023 @08:14PM (#37516560)
How would that work when someone is working on a feature/bug and has to pause switch to a another bug, then return to the 1st feature/bug

Sometimes you want to keep 2 different copies of Main with different names and state

Re:In a Git repository, where do your files live? by eru on Thursday September 14, 2023 @10:03PM (#37517332)
> Sometimes you want to keep 2 different copies of Main with different names and state

Wouldn't that just be two different branches? What does it have to do with 'main'?

Re:In a Git repository, where do your files live? by zaphirplane on Friday September 15, 2023 @07:07AM (#37521232)
> git has no idea what branch I want to push to

Maybe i misunderstood what they mean, I thought they wanted local branches to be mirrors of origin branches.

Re:In a Git repository, where do your files live? by james-skemp on Friday September 15, 2023 @07:34AM (#37521465)
Worktrees perhaps?

https://git-scm.com/docs/git-worktree

Can't recall the source I learned from anymore, but this looks pretty good: https://www.gitkraken.com/learn/git/git-worktree

I have two projects where I've got a directory that I do most of my work out of and another directory (worktree) focused on syncing from remote/assisting others on the team.

If you don't need the extras worktree gives you, clone another copy?

Re:In a Git repository, where do your files live? by eru on Monday September 18, 2023 @01:55AM (#37552706)
I use worktrees instead of multiple clones mainly so I only have to worry about remembering to 'fetch' once.
Re:In a Git repository, where do your files live? by djur on Thursday September 14, 2023 @08:49PM (#37516786)
> 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

Git has automatically tracked remote branches for years now. "git switch foo" will do exactly what you expect if "origin/foo" exists.

> if main is a protected branch, don’t let me accidentally commit to it locally

"Protected branches" don't exist in Git. They're a GitHub concept. How would you be able to fork a repository if the permissions on a remote copy of the repository prevent you from making changes to your own copy?

Re:In a Git repository, where do your files live? by eru on Thursday September 14, 2023 @10:00PM (#37517300)
I can see the case for a local UI option (perhaps even on by default) that warns you when you make changes to a local branch that's tracking a remote branch that's marked as 'protected' there. The option could also have a setting where it outright stops you from making that change.

Of course, you could always opt out of that setting.

Git doesn't know what 'protected' means, but you could teach it with a relatively small change to its code. Similarly, it might be useful to teach git about 'volatile' branches (in the same sense as C's volatile variables); a volatile branch is one where git would always checks for upstream changes first before any operation. Eg origin/main would typically be marked as both protected and volatile.

Again, volatile would be something you can override locally, but it might be useful as a default.

Re:In a Git repository, where do your files live? by djur on Thursday September 14, 2023 @10:44PM (#37517635)
The logic you're suggesting can easily be implemented with a Git hook:

https://stackoverflow.com/questions/40462111/prevent-commits...

Alternately, you can simply not check out that branch locally at all, and then you'll never have to worry about accidentally committing to it.

Re:In a Git repository, where do your files live? by WorldMaker on Friday September 15, 2023 @01:18AM (#37518764)
Also, many repo hosts have branch protection tools, and VS Code has a setting git.branchProtection to list branches which you want VS Code to remind you not to commit to, which can be handy.
Re:In a Git repository, where do your files live? by eru on Thursday September 14, 2023 @09:54PM (#37517259)
> 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.

Git actually works like that. (Though you might have to set push.autoSetupRemote to true in the config?)

However, when you have multiple remotes, it's only natural that you will sometimes need to specify which one you want.

> 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.

Git was explicitly written for Linux kernel development.

You are right that almost all other projects are simpler.

> 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.

I agree that git's UI is lacking. You don't need a from-scratch rewrite of whole system. You can just rewrite the UI only and think carefully about the defaults in the config.

Eg 'git checkout' is an incoherent mess of barely related features. 'git switch' is a later addition, and goes in the right direction.

> Treat it like a proper distributed system, perhaps even backed by a real database.

Git is very much backed by a real database. That's actually one of the stronger points of its design. You can see that the guy who started git, Linus Torvalds, has a lot of experience writing filesystems (which are also a kind of database).

Git is also very much a distributed system with no trust between the nodes necessary, including no central trusted authority. How would you 'treat' it even more 'like a proper distributed system'?

> It’s not special because the data is code. The fact that it’s treated as such is the reason it feels so weird.

Where do you get that impression from?

The main influence of being designed for code first comes in the form of the default merge driver being line oriented. But you can plug in your own merge drivers for your own data formats.

But most everything else works the same, whether you stick C source code or funny cat pictures into your repository.

Re:In a Git repository, where do your files live? by TeeMassive on Thursday September 14, 2023 @10:20PM (#37517466)
Git is much more data focused than all the other VCS. Sure, exposes details that complicates its usage for novices users, but it makes everything more maintainable and extensible in the long run.
Re:In a Git repository, where do your files live? by WorldMaker on Friday September 15, 2023 @01:46AM (#37518961)
> And yeah you can forgive all this by quibbling that git was written in a time when internet access was not ubiquitous

I don't think that's right. Git's remote concepts were built heavily on even more ubiquitous internet access than you are assuming, to some extent. Git was built where some upstreams were patches on email mailing lists. Git was built in environments where every contributor could relatively easily stand up a small server of their own (even as just a temporary server on a personal device with specified time windows) and you might have branch remotes tied to different colleagues' servers in a distributed fashion, the D in DVCS.

At the time those weren't advanced features for advanced users, those were simple features for flexible source control. There's a sort of simplicity to pull requests in email flows. There's a sort of simplicity in "hey, can you check out my branch and make notes on it, I'll serve it on my lab machine for a couple of hours so you can grab it, here's the URL." In some of those cases you don't even care to remember that remote URL after you've grabbed the branch because it will be a different IP address and port the next time they bring up that lab machine. (Git was a built in a world where there was no "origin" and multiple repos were valid representations of progress, some of them transient and as-needed, and "origin" was a name and concept that came later.)

Some of that only exists in a world that assumes internet connectivity is ubiquitous, not just access, but service hosting and upload capabilities. The internet has some strange centralizing forces making access easier but anything other than raw consumption harder.

There are certainly a lot of good reasons for some of that centralization. Whether or not is "simpler", there's a convenience on everyone sharing big centralized hosts. There's a lot of convenience of "there is mostly only one remote that everyone shares and it has a high uptime SLA and a ton of extra collaboration features in one place". There were certainly a lot of centralized version control systems before the DVCS was invented, and beyond convenience also a lot of familiarity that such centralizing operations benefited from.

It's interesting to me that in your last paragraph you think the solution is to make git a more "proper" distributed system, but one of the features you find too complex and don't like exists so much because it was defined and built as a distributed system and just isn't as convenient when working with centralized providers. git repos support multiple remotes because it was built to be distributed, git repos require to fetch remotes explicitly because it was built to be fault-tolerant in a distributed system and remotes may have very different SLAs from each other; losing access to one remote host shouldn't stop you from fetching updates from a different one. The DX there was built for a distributed system. It is mostly where we see everything revolving around some super special "origin" remote that the DX feels overly-complicated and maybe missing better "defaults". It is mostly on the internet where running a simple CLI command to spin up a quick code server on a random port on a random machine with an accessible IP address is increasingly hard that it also becomes harder to imagine why people ever needed remotes beyond that special sauce "origin" idea.

Re:In a Git repository, where do your files live? by IlliOnato on Friday September 15, 2023 @08:36PM (#37530797)
Yes, Git was not designed for your workflow, that has a single remote and a special "main" branch. It was designed for a very different workflow used in Linux development.

Git just happened to be flexible enough to be a reasonably good fit for other workflows, including GitHub-centered workflow which is relatively common. Mostly because of easy branching/merging and great support for working off-line, I guess.

However, it does not have built-in support for such workflows, their special requirements need to be be satisfied by tools and/or practices external to Git.

What you are saying is that Git is not a perfect fit for your workflow, and that this workflow is fairly common, so why there is not something better for that need? If you stopped there, your post would be perfectly reasonable from my point of view. But you called your workflow "developer experience", as if that's the only one that exists. It's kind of offensive for the people with different workflows, and so with different experience.

Anyway, I don't know the answer to your question, but my guess is that Git + external tools/practices is "good enough" for your workflow, so nobody created a completely separate system.

Re:In a Git repository, where do your files live? by Yodel0914 on Thursday September 14, 2023 @07:46PM (#37516332)
I've been using git for I guess 15 years, on a variety of server platforms (github, atlassian, MS devops, plain ssh) and branching models, with teams of various sizes, and I've never had a repo "break". Branching and merging is what git is amazing at.

The worse thing I've had happen is that someone was lazy when merging and just did a "take mine" on 100s of files, thinking that they'd do a "proper" merge later. Of course git doesn't work like that and their lazy merge had to unwound very carefully.

Re:In a Git repository, where do your files live? by nonethewiser on Thursday September 14, 2023 @08:57PM (#37516842)
> It is my experience that I have had several times where merging/branching has caused a repo to “break”

What do you mean? Like you resolve the conflict correctly and git stops working? Stops working how? That sounds very strange, and anything else just seems like PEBKAC.

Re:In a Git repository, where do your files live? by eru on Thursday September 14, 2023 @09:43PM (#37517185)
I wouldn't go so far as the term PEBKAC.

It's true that git does not 'break' from a merge; but merge conflicts (and rebase conflicts) can still be frustrating to resolve for ordinary users. And after things get too frustrating, they often do really random stuff that then might accidentally break the repo for real, or at least get it into a state where they don't have enough knowledge to recover.

Git's underlying data model is fine, but the user interface can be quite lacking. For example, 'git checkout' is a mess of almost unrelated functionality thrown together under one command.

I think the idea behind 'git switch' is a good one, and git could benefit from a complete overhaul of its user interface. Well, at least if you ignore the switching costs. Old farts like you and me have gotten used to the quirks of the bad old interface, and learned all the barely coherent options to 'git reset'.

Re:In a Git repository, where do your files live? by aliher1911 on Friday September 15, 2023 @11:12AM (#37524294)
For me git reflog was always a lifesaver when a complicated rebase or merge fails. You can always checkout previous SHA and then just return your HEAD to pre screw-up state. In case of remote repo that already ended up "broken" you can still force push to those branches, but others will have to discard theirs. Otherwise you never force push to anything shared.
Re:In a Git repository, where do your files live? by mabbo on Thursday September 14, 2023 @07:28PM (#37516176)
It's definitely not a super intuitive model, but it is a powerful one.

As I see it, git is a distributed database of snapshots of a directory of files. Every commit is a new snapshot. It's designed the way it is to achieve that goal while minimizing the space used, yet keeping an entire history of the project. It also has tools like git-diff to better compare those snapshots.

But distributed matters most because it was literally designed for managing the Linux kernel development- a large open source project with thousands of contributors working concurrently.

Merge conflicts are hard in this model because you're trying to put two snapshots together, not just two diffs.

Re:In a Git repository, where do your files live? by eru on Thursday September 14, 2023 @09:33PM (#37517108)
> It's designed the way it is to achieve that goal while minimizing the space used, yet keeping an entire history of the project

Most of git's design was done before they thought of 'minimizing the space used'. Originally, they didn't even do deltas and just stored complete snapshots for every object.

> Merge conflicts are hard in this model because you're trying to put two snapshots together, not just two diffs.

I don't think that's the case at all. Thanks to three-way-merges git has just as much access to the diffs as any other version control system when merging. It's just that in git diffs are a derived data structure, not a source of truth, but that doesn't make a difference.

Re:In a Git repository, where do your files live? by hooper on Friday September 15, 2023 @02:18AM (#37519178)
One of the ideas behind Pijul is that implicit vs explicit diffs does make an important difference sometimes: https://pijul.org/manual/why_pijul.html
Re:In a Git repository, where do your files live? by IlliOnato on Friday September 15, 2023 @06:48PM (#37530015)
I am very interested in Pijul, but the development seems to be slow. Has it reached the point where it can be used in production? (Serious question)
Re:In a Git repository, where do your files live? by hooper on Friday September 15, 2023 @09:50PM (#37531225)
I get the feeling that depends on who you ask at this point, but there has apparently been some recent development of the hosting platform (https://nest.pijul.com/). I don't know if it can have as good of a Git interoperability story as, say, jj.
Re:In a Git repository, where do your files live? by IlliOnato on Saturday September 16, 2023 @01:58PM (#37537037)
I am not interested that much in interoperability with Git. But I am afraid of data corruption, crashes, etc. Also, Pijul used to have severe performance problems in some situations. I would call it ready for production if it is stable and performant.
Re:In a Git repository, where do your files live? by eru on Sunday September 17, 2023 @08:44PM (#37550912)
Git interoperability can help with that: if you have an on-disk data format that's either compatible with git, or can easily be converted to git, you can keep your backups in git format, and work from them with git if something goes wrong.
Re:In a Git repository, where do your files live? by ta8645 on Thursday September 14, 2023 @08:15PM (#37516572)
> ClearCase [...] it is not distributed [...]

That's the key reason Git can't work the same way, and what makes it so powerful, and sometimes hard to grok.

Git is based on a Directed Acyclic Graph (DAG) of committed changes. The DAG is shared by everyone. Each commit is immutable, and only extends the DAG with a new node. You do not alter any of the DAG that other people already possess, you are creating a NEW chain of nodes connected to the DAG.

And that's it, that's how it allows anyone to make changes, at any time, on any number of systems. Because all operations are strictly additive to the DAG. Every time you commit changes, you add another immutable node onto the DAG. And at the very same moment, on another unrelated server, someone else is adding unrelated immutable nodes as well.

Later, you may obtain some of those remote changes, they can be fetched into your local repository. You can fetch them without merging them. You will just have a copy of how someone else extended the DAG. But there will be no connection between the changes you made locally, and the changes the other person made in their repository.

When you merge, you're simply updating the DAG with a new node, it will point at two, previously disconnected chains of commits. Both sides of the merge represent immutable changes that extended the DAG starting from a single commit, the branching point.

And that's what you see in merge conflicts. The first block shows what a section of code looks like in the local branch. And the second block (after the equal signs) shows what that same section of code looks like in the remote branch you're merging.

    <<<<<<<  local
    a
    X
    c
    ========
    a
    Z
    c
    >>>>>>>> remote
That's it.
Re:In a Git repository, where do your files live? by seesaw on Thursday September 14, 2023 @09:09PM (#37516912)
+1 for clearcase. I enjoyed the time I used clearcase, and never found another one that was as pleasant to use as an end user.
Re:In a Git repository, where do your files live? by Borg3 on Friday September 15, 2023 @03:33AM (#37519754)
Ugh. Ive been both using ClearCase and also were Admin of it. While as user it was pretty fine to use, as Admin I saw how complicated and fragile the whole thing was. They distributed model is absolutly terrible. You need powerfull box as a VOB server and probably be equal or even more powerfull box if you want to use dynamic views. We ended up using snapshot views.

I would choose GIT every single time over ClearCase.

Re:In a Git repository, where do your files live? by jamie_ca on Thursday September 14, 2023 @09:15PM (#37516960)
A lot of its design decisions are based around the data storage model, and tooling built to operate on those data structures. I recall a good write-up from a decade gone now, but no dice googling for it. The short version is probably:

- Everything is a blob, a text file named after the SHA1 of its content.

- Files are just themselves.

- Directories list <entry sha1> <name> for their entries (file or subdirectory).

- Commits list a Directory (the project root), and some metadata about the commit like the author, commit message, and the parent(s) of the commit.

- A branch then is just an end-user-named reference to a commit's hash.

Everything flows from that - SHAs are reused, if you're doing a diff and two directory entries have the same sha referencing a file, there's no change. Switching a branch is modifying the special HEAD branch content, and recursively walking it to rehydrate the filesystem (and comparing to the previous checkout to optimize, skipping whole directories that don't change).

Re:In a Git repository, where do your files live? by yencabulator on Friday September 15, 2023 @12:00PM (#37525095)
Re:In a Git repository, where do your files live? by wayfinder on Thursday September 14, 2023 @09:21PM (#37517014)
I think Git is conceptually simple... each commit is just conceptually a diff from a previous commit -- possibly from two commits. Branches and tags are just pointers to a commit.

A merge is when you join two commits and thus may result in one merge conflict, while a rebase is resetting your branch to some other target commit and then /re-applying/ _each_ of your commits on top, which may generate more than 1 merge conflict (due to each _one_ of your commits effectively being re-committed all over again) but hides the fact that you applying old changes to a newer base.

But the tooling around Git is not great. I think showing merge conflicts properly so you don't mess them up is also tooling issue more than anything.

I'm going to plug this app called SmartGit which I have no relationship with that I don't think a lot of people have tried but it's awesome. Doesn't obscure anything about Git and shows merge conflicts well IMO. Costs $ though.

Re:In a Git repository, where do your files live? by eru on Thursday September 14, 2023 @09:37PM (#37517134)
> I think Git is conceptually simple... each commit is just conceptually a diff from a previous commit -- possibly from two commits. Branches and tags are just pointers to a commit.

That's backwards. Git commits are complete snapshots of the state of your repository at the time. You can compute diffs between arbitrary commits, be that between child and parent commits, or completely unrelated commits.

Have a look at https://stackoverflow.com/questions/4129049/why-is-a-3-way-m...

Re:In a Git repository, where do your files live? by wayfinder on Friday September 15, 2023 @12:45AM (#37518543)
Oh I know. I do that all that time. (And in SmartFGit, you can select any two commits.)

But I said conceptually and that’s how I see them and it works for me.

Re:In a Git repository, where do your files live? by OskarS on Friday September 15, 2023 @04:59AM (#37520289)
Conceptually, though, that's the wrong model. Pijul works like that, but git does not: commits are not diffs, they are full snapshots of the repository, including history. If you cherry-pick a commit from one branch to another, that's an entire new commit, it's not just "this patch moved from one branch to another". If your idea of a commit is "it's a diff to the previous commit", you'll get into trouble.
Re:In a Git repository, where do your files live? by globular-toast on Friday September 15, 2023 @05:47AM (#37520606)
Yes and no.

When you do a checkout or reset etc. you are indeed operating on snapshots. You're just saying "get me this version right here".

But when you do cherry-pick or rebase etc, git is operating on diffs. A cherry-pick doesn't set your head or workdir to that version[0], it applies the changes to a new commit that sits on top of your current head. Similarly, a rebase walks through the changes and applies each one to the target.

Commits and diffs are a duality and it matters not one bit how git stores them underneath. You can always calculate one from the other.

[0] If you did want to do that for some reason then git reset will do it for you. That sets your current branch to that commit and with --hard it makes your workdir match. `git checkout <sha1> .` makes your workdir match that older commit, but it doesn't do deletes. If you want to make just your workdir match an older commit the only way I know is something like: `git reset --hard <sha1>; git reset --soft HEAD@{1}` which can be read as "set my current branch to be at sha1 and make working directory match that snapshot exactly, then set my branch to be at where it was before that operation, leaving my workdir alone". It's not a very common thing to want to do.

Re:In a Git repository, where do your files live? by IlliOnato on Friday September 15, 2023 @08:14PM (#37530639)
> Branches and tags are just pointers to a commit

Technically that's correct, but it is not how branches are thought of and used. Conceptually a branch is, well, a line of development, a sequence of commits with a name. (Actually it is not necessary just a sequence, but this is not important here)

I think the implementation of branches in Git as just a kind of fancy tags is one of the sources of confusion about/around Git.

And I love Git, don't get me wrong! But some things in it make things harder than necessary.