3 ms·
I think the staging area is a horrible idea. It greatly complicates the UI ("diff --cached"? Really?) without providing many benefits (if you want to commit jus
by StavrosK 13y ago
I think the staging area is a horrible idea. It greatly complicates the UI ("diff --cached"? Really?) without providing many benefits (if you want to commit just some files, you could simply specify the names at commit time.
I really love bzr's UI in this respect, and I understand Mercurial is similar too.
- barrkel 13y agoYou could use git commit -a, but I've found that seldom does what you want. Usually, you don't want to commit all files, because you've made unrelated changes to configuration, debug logging etc. And sometimes you don't even want to commit all the changes in a single file, and git lets you choose which diff sections ("hunks") to commit with git add -p. I came to git already knowing what a dag was, and after having cobbled together my own patch management system to make up for deficiencies in svn, so I didn't have much difficulty intuiting almost the whole of git after very little time.
- StavrosK 13y agoI came to git from bzr, and I always use commit -a these days. If I want to ignore a file, I just specify the ones I actually want to commit, and it works just fine for my purposes (I don't generally make irrelevant changes). YMMV, of course.
- Nervetattoo 13y agoYou couldn't run tests only on your staged changes pre-commit without the staging area. Right now my pre-commit hook stashes any non-staged changes, from inside the same files that has staged content, and then runs tests. This ensures I can create commits with just the stuff that works of my changes without first removing the ongoing work. The staging area surely adds complexity, but if you do not like it then simply don't use git.
- StavrosK 13y ago> This ensures I can create commits with just the stuff that works of my changes without first removing the ongoing work. If I have ongoing work I want to remove, I just stash it, as you said. I don't need a staging area to stash things, and it's pretty rare that I'll have unrelated work anyway. > The staging area surely adds complexity, but if you do not like it then simply don't use git. Ah, the old "your arm hurts? Just cut it off!" solution. Yes, I will just not use git, I will just email my team diffs.
- richardwhiuk 13y agoIf you are using a recent git version, you can use diff --staged instead - diff --cached is there for existing users. Specifying names at commit time is really horrible - it's more error prone and harder to get a diff of exactly what you are committing. You can also commit part of files using the staging area by doing git add -p. My workflow is often git add -p; git diff --staged; git commit
- ghayes 13y agoAnd, alternatively, you can use `git commit -a` if you want to bypass the staging area.
- gurkendoktor 13y agoI am avoiding git's CLI like the plague, but IMHO the staging area is awesome to use with a GUI like Git Tower - it was never that easy to stage (and commit) line by line, leaving out stuff like printf debugging that shouldn't go down the wire. Then again, I guess the GUI could just implement the staging area itself and pass line numbers to "git commit" :)
- StavrosK 13y agoYes, exactly. Atlassian's client (I forget the name) has that feature too, and it's great, but it can just do it directly if there's no staging area (as it does with hg, I assume). If you're in the CLI, you can use the exact same command you use to stage stuff to commit stuff, and then there's exactly zero benefit.