To each their own, but I always saw the staging area as an anti-pattern that also needlessly complicated git's mental model.
With the staging area, you don't even know if the commit builds if you commit selectively, and manual adding is error-prone.
The traditional "clean" way has been to stash unwanted changes temporarily, then commit the rest.
> With the staging area, you don’t even know if the commit builds if you commit selectively, and manual adding is error-prone.
I get conceptually why it’s desired to have things build properly on every commit but I just haven’t seen people actually make use of that. In my team’s current code base, we have the commits in a given PR auto-squash down into one commit which I’ve liked quite a bit
It's the lazy and pragmatic solution for those who aren't really comfortable with git / VCS.
> With the staging area, you don't even know if the commit builds if you commit selectively
You should always use server-side CICD.
> and manual adding is error-prone
That's a UI problem. I've been manually selecting code with Magit for years and it's very effective.
> You should always use server-side CICD.
First, server-side CI is usually only running for the last commit, so if you have a series of commits pushed at once, this doesn't really help.
Second, it's not even so much about the validating a commit (which, for intermediate steps, it might not do), but so that each commit hangs together and a change as a logical unit doesn't exist partly in one and partly in another commit [1].
Conceptually, the whole staging process flies in the face of the idea that a commit should represent an atomic repo change and feels more CVS-like.
> That's a UI problem. I've been manually selecting code with Magit for years and it's very effective.
There are two counterpoints I would like to make here. One is that if you need additional tooling to work around a problem in an existing tool, that does not mean the original tool does not have a problem.
The other is that better tooling does not mean that the increased error rate from unnecessary manual steps goes away; it can mitigate it, but it does not do away with the consequences of e.g. inadvertent lapses of attention.
And realistically, in most cases it is just unnecessary extra work for no good reason.
[1] Mind you, there's the problem that commits are really used for two different things, one is to capture conceptual steps and one is to to do quick save of the repo state, and no existing VCS does a good job of reconciling these two different purposes.
> Second, it's not even so much about the validating a commit (which, for intermediate steps, it might not do), but so that each commit hangs together and a change as a logical unit doesn't exist partly in one and partly in another commit [1].
That's what review is for.
> Conceptually, the whole staging process flies in the face of the idea that a commit should represent an atomic repo change
No it doesn't. The staging area is precisely what allows you to carefully build a commit. Before git, we had to do the same by backing up the modified files somewhere else and creating a commit, then bringing them back. I used to use CVS, then Subversion, then a mix of Darcs and Arch, before git finally solved it.
> One is that if you need additional tooling to work around a problem in an existing tool
You're assuming there's a problem. There isn't.
> Mind you, there's the problem that commits are really used for two different things, one is to capture conceptual steps and one is to to do quick save of the repo state
Using commits to save state is bad and I've forbidden it in my team. Jujutsu makes it more convenient so that uncommitted state is itself a special commit that gets pushed to the server, but the real solution is what Google's SrcFS does: workstations checkout code on top of a FUSE filesystems that really gets saved on the server side, so state can never get lost on a single machine.
That’s something I have the same thoughts on, because long time ago I used CVS/SVN and staging area with stashing was exactly the answer for what you wrote.
Combined with stashing you can quickly build to see if the commit builds.
Git supports all of it and people and jj are just complicating it by “let’s skip all of that and make a commit” because they don’t see it actually is simpler.
I just see how in 5 years someone who would be used only to jj will come over and re-invent staging and stashing “because I want changes but I don’t want to make a commit”.
If you look at my initial comment, you will notice that stashing is exactly what I suggested as the traditional clean way of doing it. The thing is that if you already have stashing/shelving, you don't need a staging area for commits at all [1].
And a staging area is arguably the more error-prone and less ergonomic approach, giving rise to more UI complexity like git diff --cached, git diff HEAD, and plain git diff all being necessary functions. Or the git reset --soft/--mixed/--hard triad.
This ultimately results from the design decision that the staging area is a revision in all but name (it is a set of changes, after all), but cannot be addressed as one, so additional UI ceremony is needed. (See e.g. Mercurial and Sapling, both of which allow you to add and remove changes to and from the current commit, and thus avoid this unneeded complexity.)
[1] That git also uses the staging area for merges is a separate issue.
> If you look at my initial comment, you will notice that stashing is exactly what I suggested as the traditional clean way of doing it.
Stashing might be "clean" - but "clean" just means primitive in this sense, it's a bad thing - but it destroys local state and I don't want that.
> And a staging area is arguably the more error-prone and less ergonomic approach, giving rise to more UI complexity like git diff --cached, git diff HEAD, and plain git diff all being necessary functions. Or the git reset --soft/--mixed/--hard triad.
The problem is in the UI, all those operations can be expressed much more naturally if one used a good UI like Magit.
> This ultimately results from the design decision that the staging area is a revision in all but name (it is a set of changes, after all), but cannot be addressed as one, so additional UI ceremony is needed. (See e.g. Mercurial and Sapling, both of which allow you to add and remove changes to and from the current commit, and thus avoid this unneeded complexity.)
The staging area is not meant to be addressed, but only to be temporarily used in a brief process of selection of changes to be included into a commit. Keeping changes for more than a few minutes in a staging area is the wrong way to use it.
> That's what review is for.
This would mean that you're changing already pushed commits, leading to mutable shared state, which is also not a desirable situation. (Aside from the fact that fixing up commits can be a somewhat painful business in Git.)
Also, this seems to be an inconsistency in your position. If it is okay to have poorly built commits because you can fix them after code review, why is building them carefully in the first place important?
> No it doesn't. The staging area is precisely what allows you to carefully build a commit. Before git, we had to do the same by backing up the modified files somewhere else and creating a commit, then bringing them back. I used to use CVS, then Subversion, then a mix of Darcs and Arch, before git finally solved it.
This is interesting, because Arch already had the concept of a stash (via the oddly named `tla undo/redo`, even if like much of Arch, it was a bit primitive). In any event, stashing/shelving as a concept already does what you want a staging area to accomplish, as I had pointed out above, without the problems introduced by the staging area. In general, the "backing up the modified files somewhere" was made unnecessary in most version control systems a long time ago.
> Using commits to save state is bad and I've forbidden it in my team. Jujutsu makes it more convenient so that uncommitted state is itself a special commit that gets pushed to the server, but the real solution is what Google's SrcFS does: workstations checkout code on top of a FUSE filesystems that really gets saved on the server side, so state can never get lost on a single machine.
You seem to have misread my statement, as I pointed out that this is a problem; we are not disagreeing here. That git does not really have a good way to support the functionality of saving repo state is the actual issue, but a shortcoming that is shared by almost all VCSes.
Doing this at the file system level is also not really adequate. It does not replicate the functionality of temporary snapshots and if it did (like the local history in JetBrains IDEs), it would be cumbersome.
> This would mean that you're changing already pushed commits, leading to mutable shared state, which is also not a desirable situation.
A PR is a temporary container, and those commits there are in no meaningful sense "published" so they should be considered mutable.
> If it is okay to have poorly built commits because you can fix them after code review
Nowhere did I say that. Commits should be of very good quality, but there are diminishing results from putting safeguards over safeguards into the CI/CD logic: some qualities, like the conceptual integrity of a commit, should be enforced through review not code (CI/CD checks).
> stashing/shelving as a concept already does what you want a staging area to accomplish
No no no. I want to keep my local state while selecting a subset of those changes to be sent to the server for testing. Stashing destroys that, I never want it.
> In general, the "backing up the modified files somewhere" was made unnecessary in most version control systems a long time ago.
Actually it wasn't. I want my local state to be kept exactly as it is, in an uncommitted limbo, and the only VCS I've encountered that fixes that from the points of view of safety, clarity and ergonomy is Google's Piper with its SrcFS local component.
> Doing this at the file system level is also not really adequate.
It is, and I'll point again to Piper: every compilation attempt and every time one updates a Piper Changelist results in a named (numbered) snapshot that can be used in Critique (the UI) for comparison, either as NEW or OLD state. It's very sophisticated and works marvellously.