5 ms·
Agreed; the ability to commit a subset of the changes in your working directory makes it far easier to make a large number of small, focused, single-change comm
by JoshTriplett 13y ago
Agreed; the ability to commit a subset of the changes in your working directory makes it far easier to make a large number of small, focused, single-change commits. Tools like "git add -p" make that even easier.
If you ignore the staging area, you become much more tempted to make several unrelated changes in one commit, rather than untangling them.
- snogglethorpe 13y agoI agree. The git UI has some warts, but the staging area isn't one of them. It's an extremely useful feature, and a true improvement over traditional SCM interfaces. It's nice to see people wanting to improve git's interface, but please, don't just dumb it down....
- lucian1900 13y agoThe staging area doesn't really help much with that, though. Too often there are unrelated changes to the same file, which are precisely as inconvenient to split up as those in separate files without a staging area.
- Mithaldu 13y agoThe staging area makes it possible to split them up by selectively adding lines to it with `git add -p` or the much superior `git gui`.
- jdpage 13y agoThat's exactly what git add -p does, and it's vastly more convenient than when you don't have a staging area.
- 6ren 13y agoI find the problem with git add -p is when you have changes that are overlapping - e.g. you've tried a few variations of implementing something, that have many commonalities - but sadly you didn't commit them as you went along, but now what to, for reference in case they are needed later. git add -p doesn't help tease them apart, because its hunks are based on diffs, and the granularity usually does not coincide with actual changes (nor syntax or semantics of the languages). Which is really expecting a bit too much! Diff's implementation of LCS algorithm is incredibly fast and works amazingly well for changes in different places. So what I do is edit the file to what I want, stage and commit, then undo and continue. This doesn't really use the staging area, and I'm hoping there's a better way to do it... if anyone can think of one?
- Mithaldu 13y agoI don't use `git add -p` much, since i commit exclusively with `git gui`. The reason being that `git gui` allows me to stage single lines, or hunks AND allows me to change the granularity of hunks on the fly. Even if that isn't an option for you, i'm sure that `git add -p` has a command to modify hunk granilarity.
- oyvindn 13y agogit add -p, then "s" until it can't split the hunk any more, then "e" to edit the hunk manually?
- 6ren 13y agoyou can do it, but I've found in some cases that modifying patches (including "e") becomes more complex than stating the desired result directly.
- blktiger 13y agoOne thing that I've found handy on a few occasions is Atlassian Source Tree. You can stage individual lines, not just individual hunks. Sometimes that makes it much easier to pull apart the changes.