7 ms·
I'm surprisedly the staging-area hate. Does it really violate peoples' assumptions? I like the ability to make a big, complex change and checkpoint stable port
by gumby 9y ago
I'm surprisedly the staging-area hate. Does it really violate peoples' assumptions? I like the ability to make a big, complex change and checkpoint stable portions (subsets) of the work as I go.
- CJefferson 9y agoMy problem with the staging area is it produces commits which never "exist" (that is, that code was probably never compiled/tested in isolation). I'd be happier if the staging area was handled at the filesystem level, give me a directory which at all times contains the staging area, so I can test it.
- jononor 9y agoYour CI system can test those commits in isolation. I frequently push supposed-to-be-stable commits like that alone to my working branch on Github, so Travis CI can tell me if I have a problem. Though I'm quite picky about commits, that each merge point into mainline (master) is tested is what is most important to me. Github PRs with Travis CI for instance enforce that pretty OK. If I don't bother to do a PR, and the changes as a linear set upon master, I like to use git merge --no-ff master to force a merge commit.
- maxxxxx 9y agoTo me staging is the best part of git. I don't want to commit all the time so I slowly stage changes that I think are OK. Once the feature is done I can do a full commit. Perfect!
- spiznnx 9y agoThe author purports that this can be achieved without staging. For example, you could slowly commit small changes that you think are ok on a work-in-progress feature branch with `git commit -p --allow-empty-message`. When you are done you could squash rebase + message rewrite. While currently this workflow is clunky, it could be made to work with the same nice semantics of your workflow, and not have a staging area at all.
- maxxxxx 9y agoSure. I can get the same result I can get with simple staging with a complicated squash workflow. But why would I do that? I have seen people get in trouble with rebasing and generally while manipulating history but never with the staging area.
- maxxxxx 9y agoI should add. I always use a GUI like SourceTree for staging. With the command line it's much less fun.
- tonfa 9y ago> I have seen people get in trouble with rebasing and generally while manipulating history but never with the staging area. I think that's what mercurial tries to solve, it makes manipulating history safe (by tracking the state of the commits, whether they were published or not for example, and always keeping all the history but hiding it after it was rewritten).
- gmueckl 9y ago90% of VCS commits are simple enough to not need staging in my experience. That you can stage your changes does not mean that you need to be forced to do that. This is the point the article tries to make: streamline the workflow, but do not remove the feature for power users (people like you).
- OJFord 9y agoI believe there's a flag to `commit` that effectively does `add .` first. I disagree with your statistic though - I can't tell you what the flag is precisely because it's almost never what I want; so I never use it and haven't learnt it. I think these things just vary with workflow.
- mrich 9y agoJust for completeness sake, the command to do that would be git commit -a It does an implicit git add -u (which does not add new files not yet part of the repo)
- gmueckl 9y agoSo you disagree based on your personal experience? That is fine. I base my observation on what the people around me were using in various environments, so I am actually fairly confident that this can be generalized. This is the best I can do unless someone makes some representative statistics over a broad user base.
- qznc 9y agoI record my uses of each command and the current counts are the following (g is my shell alias for git): 161 g cap # commit --patch --amend 170 g adu # add -u 205 g add -p # add --patch 277 g ci # commit -a 484 g cip # commit --patch At least, I use it a lot. ;)
- rbehrends 9y agoThe thing is that you don't need a staging area for that. The staging area is an unnecessarily complicated way to address this particular problem. More importantly, the article is about the staging area being there by default.
- carussell 9y agoPartial commits through piecemeal staging is great as a poweruser's tool, like rebase. But it's beyond weird that anyone thought it was a good idea to make people deal with staging for every commit. It doesn't even have to go away. (And on that note, I'm bummed that the conclusion in the article is to do that, especially because everytime this comes up, there's an uproar.) But, jeez. Just tuck it away so futzing with it is an opt-in decision for the 5% of the time that you need to make sure you aren't committing all of your changes. (And on note #2, if a person is doing partially staged changes more often than that, my question is why? What kind of chaotic, stream-of-consciousness style of development leads to that, and is it even producing good results? It doesn't take especially careful planning to not end up in the scenarios where partially committed changes is the answer.)
- enzanki_ars 9y agoI have ADHD, so often as I am working on one feature, I will begin accidentally working on another unrelated feature along side it. I rely on staging a lot to ensure that each commit has only the parts that it needs.
- jcranmer 9y agoComing from someone who learned hg well before git, and who's now being more or less forced to use git long after developing comfortable hg workflows, the staging area feels like a half-baked implementation of what it's supposed to be doing. I'm used to thinking of commits as atomic commits--roughly, each commit is the smallest change that atomically makes sense. So you should be able to use the staging area to build up that commit as you find more pieces to make it in. But while I'm slowly hacking away at this commit, I talked with someone else and decided to try an idea which turns out to be a small commit. But I've already got this half-built-up commit that's staged, so I need to commit that to make the new commit, and then somehow reverse the patches and restage the commit (which is something that's well outside my git comfort level). What hg has is a few different features that make it possible to build up not just a single commit but an entire commit sequence and do operations on that commit sequence (like reorder them). The git staging area is kind of a weak version of that, but it ends up being in limbo: too complex for the simple just-commit-everything model but too simple for try-to-craft-the-public-changelog model. Edit: the model I adapted to from my hg workflows is effectively commit --amend. Mercurial has an interesting way of doing history tracking such that if I really need to, I can actually follow the history of the "oops, I need to change these commit because I missed a compiler failure" or "I forgot to save this file before committing," which is a feature that git doesn't have. If you promoted amending the last commit, you wouldn't need a staging area to build up a commit, the last commit does it for you already.
- Joky 9y agoI don't know mercurial, and I agree about the limitation you mention for stashing the index. That said if I need to do a refactoring or something else while I have an unclean tree, I stash before doing it, then commit it, and then unstash my work. > What hg has is a few different features that make it possible to build up not just a single commit but an entire commit sequence and do operations on that commit sequence (like reorder them). Again, I've never used hg (beyond a simple tutorial), but you can commit frequently with git (every few other changes "WIP") and reorder / fuse / edit later through interactive rebase.
- enzanki_ars 9y agoWith git, you can stage line by line, file by file. You don’t need to commit everything at once. Also, you can add the lines you want in to staging, then use the stash feature to temporarily save lines that you don’t want in the commit. This allow you to test the commit without all of the extra lines you don’t want. I would highly suggest reading Pro Git [0], a well written book on not only how to use git, but also the best practices, common workflows, and some of the internals in to how git works. Many refer to it as the essential book on git. [0]: https://git-scm.com/book/en/v2 https://git-scm.com/book/en/v2
- angelsl 9y agoThis, exactly. What's so hard about one more command? If you really want a "save all" , just `git commit -a`.
- inimino 9y agoAs the author points out, it is an unnecessary primitive, once you learn about things like commit —amend, which you will inevitably eventually learn about anyway. Adding redundant ways to do the same thing is not the way to make a tool approachable. The basic problem is that git was designed to solve Linus’s problems, and Linus’s problems are not your problems. However, because of network effects, most of us end up using the same tool.
- mercutio2 9y agoHow does commit --amend in any way solve the same problem as the staging area? If I’ve got a big change which I want to split into three small internally consistent changes, with each change overlapping in many files, how in the world would --amend help?
- inimino 9y agoIt solves the problem I was directly replying to: > I like the ability to make a big, complex change and checkpoint stable portions (subsets) of the work as I go. However, it does not replace all use cases of the staging area, which is why I gave it only as an example. Of course, `commit --amend` with `-p` could solve your problem as well. Alternatively, “create a new, 'pending’ commit, without a commit message, don’t point HEAD to it yet, and change most of the commit-related commands to modify this commit until it is finalized” also solves all the use cases of the staging area, because that is what the staging area is, but it is presented in a much more confusing way and ends up being yet another new concept for git beginners to grasp.
- mercutio2 9y agoFair points. After thinking about this more, I find myself agreeing that in terms of beginner friendliness, the combination of incredible name confusion and the relative paucity of use cases where it’s necessary make the staging area an interesting area for significant change in the git defaults.
- paxys 9y agoBut why not use a mechanism that already exists - local commits. That way you also get a complete history of changes (including rollbacks), can write incremental commit messages, and can squash everything partially or completely at the end.
- qznc 9y agoI made myself a few alias to use this approach. After a few months of use I can say staging is practically unnecessary for me. There were a few edge cases, but maybe I was just falling back to known solutions. I'm in favor of dropping staging.
- xenomachina 9y agoHow do you test the thing you're actually committing without everything else in your working tree contaminating your test? There are ways to do this using stash but if you stash before you commit, you get merge conflicts when you pop the stash. The workaround I've seen is to commit before you stash, but that means you're also committing before you've actually tested that change, which seems pretty broken, IMHO.
- kazagistar 9y agoCommits are just a bit of local data. Until you push it out somewhere public, it's all just a big mushy pallette to do with as you will.
- imtringued 9y agoCreate a new branch for each issue where you create broken untested garbage commits with meaningless messages like "Fix". When you're done: git checkout master git merge --squash <branch_name> git commit -m "<Real commit message here>"
- sunny256 9y agoI've created a script for this, it applies the staged changes to a fresh clone and executes the command you specify. To quote from --help: If you have lots of unrelated uncommitted changes in the current repository and want to split up the commit, how can you easily check if the changes passes the test suite? With all the other unrelated changes it can be hard to make sure that only relevant changes becomes part of the commit, and that they don't result in regressions. This script clones the repository to the directory ".testadd.tmp" in the current directory and applies the staged changes there (unless -u/--unmodified or -p/--pristine is specified), chdirs to the same relative directory in the clone and executes the command specified on the command line there. It's available from https://github.com/sunny256/utils/blob/master/git-testadd https://github.com/sunny256/utils/blob/master/git-testadd and the test suite (place it in a subdirectory below the script) is at https://github.com/sunny256/utils/blob/master/tests/git-testadd.t https://github.com/sunny256/utils/blob/master/tests/git-test... It's stable, and I've been using it almost every day for 1.5 years. It also works with binary files.