It removes the staging area, which also removes one of the more powerful tools in git for teasing apart work into distinct ideas, whether for creating a sensible commit history, or to separate "tangled" work into different branches. For example:
1. Write code
2. Realize it's more than you want to commit at a go
3. Stage just the files (or hunks, using `git add -i`) you want
4. git stash
5. confirm tests still work
6. git commit
7. git stash pop
8. continue working, committing, etc.
I certainly understand the desire for cleaning up Git's CLI[1], but the staging area is one of those truly new offerings in Git w.r.t. legacy VCS. One that requires cognitive effort to learn but becomes a very useful tool in practice.
The staging area is only a powerful and necessary tool if you believe in the Commits Are Immutable rule (i.e. "don't rewrite history"). If you believe in that rule then you have to have a special mutable commit called the staging area, for when you're halfway through creating a commit.
But if you believe in rewriting history, then you can just use the tip of the working branch as a staging area. This would eliminate a whole slew of nonorthogonal git commands.
Personally I believe that branches should be explicitly designated as mutable (private "work" branches) or immutable (published branches): this gets you the best of both worlds. It's a shame Git doesn't have any tools to enforce that distinction.
It's a shame Git doesn't have any tools to enforce that distinction.
Because, by design, Git can't ever know. Example one: a read-only repo can be fully cloned, meaning that all the branches therein should technically be "public". But the cloned repo is read-only so there's no way to add metadata to its branches. Example two: a developer "publishes" her entire repo to a wholly private offsite remote at the end of each day as a backup mechanism. All branches should be marked "public", but that would be wrong since they weren't exposed to any other person. I've recently worked in a shop where all <name>/<topic> branches in the main repo were considered logically private unless by prior agreement. Publishing was defined as merging to master; rebasing a logically private branch was perfectly OK (and frequently mandatory).
More to the point: it's not git's job to be overly "smart", especially in ways that require mind-reading. git provides a powerful "algebra of version control", where at some point even the "porcelain" commands can really be seen as "plumbing". In this light, I'm all in favor of higher levels of workflow porcelain. In fact, many larger teams I've worked with accrete such a layer out of necessity. Communicating and performing policy as folk knowledge eventually fails to scale, and tools pick up the slack. So the workflow you describe could be encoded as the Opinionated Policy of a tool on top of git which fills in the missing info in the scenarios above.
This reveals something I find disappointing about TFA: the lack of design exposition about its approach. Also, it appears to be trying to address VCS design without actually talking at all about what's known about the problem space to date. IMO this stands in stark contrast to the current generation of DVCS tools where the players (git, hg, bzr, darcs, etc.) each communicated around a set of concrete lessons learned from prior VCS systems.
Except that in practice people tend not to perform steps 4, 5 and 7. They then commit non-working code and honestly believe that their commit is OK, because they saw all tests pass.
So, what, if people aren't using the full power of Git, the response is to remove that power? That seems completely backwards. The response should be to educate people on proper development practices.
Sometimes it just feels like not removing the nuclear missile launch button from a cage with monkeys arguing that we should not remove the power of nuclear weapons just because monkeys are unable to understand the geopolitical situation.
I think the people well-versed enough in git to use "git add -p" to review their own changes, and commit them separately, are the same people that would correctly test their commits.
At least from my small sample size of people, that is true.
This is definitely not true for the outsource companies here in the 3rd world.
It gets even worse when you face people who have used SVN for years. Once they realize that they can commit non-working code on their feature branch as long as the result of the final merge into master is OK, they start to dump random work-in-progress stuff into git repo. As the result, blame and bisect are completely broken, but who cares, that's another developer who would feel the pain trying to make sense from the changeset history two years from now, not you.
One way to mitigate that is to always squash-merge the suspect work. In some orgs, it's really hard to establish a culture of good "git hygiene". Typically CI is already branch-focused, and the merging process after CI/review/etc. is tailored to just throw out the "noise" from the incoming branches.
This also handles issues such as staff who just don't get that long-lived, continually remerged (from master) branches are evil when viewing history using `git log --graph` or similar GUI views.
Nifty trick: use `git stash --keep-index save` to leave the staged changes around while stashing the unstaged ones. Then run your tests, muddle around and fix things as necessary, and commit. Then `git stash pop` and you have all your changes back. It seems obvious to me that this behavior should be the default for `git stash` but it isn't. Thank goodness for aliases.
Agreed, I don't tend to use `git add -i` much directly either. I use editor integrations and/or a GUI tool that allows line-by-line staging. I rather like Git Tower's[1] approach: it's easy to stage directly in the diff view either by hunk or by selected lines. This works nicely because most of the time the diff hunk(s) are OK, and I only need to mess with a selection in the less common cases.
You can, but last time I tried it was only via editing the diffs ('e' command in `git add -p`), which is unpleasant and sometimes pretty annoying (ah, how many times I missed the leading space on context line to have it shout at me with incomprehensible errors). (And yeah, I'm just using `git gui` for this now.)
Comments
It removes the staging area, which also removes one of the more powerful tools in git for teasing apart work into distinct ideas, whether for creating a sensible commit history, or to separate "tangled" work into different branches. For example:
I certainly understand the desire for cleaning up Git's CLI[1], but the staging area is one of those truly new offerings in Git w.r.t. legacy VCS. One that requires cognitive effort to learn but becomes a very useful tool in practice.[1] Cf. Steve Losh's infamous "Git Koans": http://stevelosh.com/blog/2013/04/git-koans/
The staging area is only a powerful and necessary tool if you believe in the Commits Are Immutable rule (i.e. "don't rewrite history"). If you believe in that rule then you have to have a special mutable commit called the staging area, for when you're halfway through creating a commit.
But if you believe in rewriting history, then you can just use the tip of the working branch as a staging area. This would eliminate a whole slew of nonorthogonal git commands.
Personally I believe that branches should be explicitly designated as mutable (private "work" branches) or immutable (published branches): this gets you the best of both worlds. It's a shame Git doesn't have any tools to enforce that distinction.
Because, by design, Git can't ever know. Example one: a read-only repo can be fully cloned, meaning that all the branches therein should technically be "public". But the cloned repo is read-only so there's no way to add metadata to its branches. Example two: a developer "publishes" her entire repo to a wholly private offsite remote at the end of each day as a backup mechanism. All branches should be marked "public", but that would be wrong since they weren't exposed to any other person. I've recently worked in a shop where all <name>/<topic> branches in the main repo were considered logically private unless by prior agreement. Publishing was defined as merging to master; rebasing a logically private branch was perfectly OK (and frequently mandatory).
More to the point: it's not git's job to be overly "smart", especially in ways that require mind-reading. git provides a powerful "algebra of version control", where at some point even the "porcelain" commands can really be seen as "plumbing". In this light, I'm all in favor of higher levels of workflow porcelain. In fact, many larger teams I've worked with accrete such a layer out of necessity. Communicating and performing policy as folk knowledge eventually fails to scale, and tools pick up the slack. So the workflow you describe could be encoded as the Opinionated Policy of a tool on top of git which fills in the missing info in the scenarios above.
This reveals something I find disappointing about TFA: the lack of design exposition about its approach. Also, it appears to be trying to address VCS design without actually talking at all about what's known about the problem space to date. IMO this stands in stark contrast to the current generation of DVCS tools where the players (git, hg, bzr, darcs, etc.) each communicated around a set of concrete lessons learned from prior VCS systems.
Except that in practice people tend not to perform steps 4, 5 and 7. They then commit non-working code and honestly believe that their commit is OK, because they saw all tests pass.
So, what, if people aren't using the full power of Git, the response is to remove that power? That seems completely backwards. The response should be to educate people on proper development practices.
Sometimes it just feels like not removing the nuclear missile launch button from a cage with monkeys arguing that we should not remove the power of nuclear weapons just because monkeys are unable to understand the geopolitical situation.
Full Ack!
(awesome metaphor btw)
I think the people well-versed enough in git to use "git add -p" to review their own changes, and commit them separately, are the same people that would correctly test their commits.
At least from my small sample size of people, that is true.
This is definitely not true for the outsource companies here in the 3rd world.
It gets even worse when you face people who have used SVN for years. Once they realize that they can commit non-working code on their feature branch as long as the result of the final merge into master is OK, they start to dump random work-in-progress stuff into git repo. As the result, blame and bisect are completely broken, but who cares, that's another developer who would feel the pain trying to make sense from the changeset history two years from now, not you.
One way to mitigate that is to always squash-merge the suspect work. In some orgs, it's really hard to establish a culture of good "git hygiene". Typically CI is already branch-focused, and the merging process after CI/review/etc. is tailored to just throw out the "noise" from the incoming branches.
This also handles issues such as staff who just don't get that long-lived, continually remerged (from master) branches are evil when viewing history using `git log --graph` or similar GUI views.
Nifty trick: use `git stash --keep-index save` to leave the staged changes around while stashing the unstaged ones. Then run your tests, muddle around and fix things as necessary, and commit. Then `git stash pop` and you have all your changes back. It seems obvious to me that this behavior should be the default for `git stash` but it isn't. Thank goodness for aliases.
Having untangled ideas using hunks, when diff doesn't choose the desired boundaries I'm not quite sure it's worth it. Certainly an engaging exercise.
Agreed, I don't tend to use `git add -i` much directly either. I use editor integrations and/or a GUI tool that allows line-by-line staging. I rather like Git Tower's[1] approach: it's easy to stage directly in the diff view either by hunk or by selected lines. This works nicely because most of the time the diff hunk(s) are OK, and I only need to mess with a selection in the less common cases.
[1] http://www.git-tower.com/
You can split hunks down to individual lines.
Also git-gui can stage individual lines.
You can, but last time I tried it was only via editing the diffs ('e' command in `git add -p`), which is unpleasant and sometimes pretty annoying (ah, how many times I missed the leading space on context line to have it shout at me with incomprehensible errors). (And yeah, I'm just using `git gui` for this now.)
I once recovered a commit that someone had staged and reverted.
Even though he had never checked in code it was still saved into the VCS. That is pretty powerful.
You mean git stash --keep-index in 4) right?