Hacker News new | ask | show | jobs
by skrebbel 5453 days ago
> It's one of the great things about Git; without it, you wouldn't be able to create commits from a subset of the difference between your working directory and HEAD.

I never understood that. I can do this just fine even with TortoiseSVN. Just click "commit" and select the files you want to include in this commit. I don't see how I need to keep yet another data structure / piece of "state" in the back of my head for that. I definitely don't see why I have to look for an alternate career because of that.

Am I missing something?

3 comments

The benefit that the index gets you in such a situation is that sometimes you are working on two unrelated changes at the same time, but they both touch the same file. Git (using the -p flag to the add command) lets you interactively select portions of a file to add to the index.

The interface is pretty simple: it just shows you each small piece of diff to the files you are adding, and you say whether you want to include that bit of diff in the index or leave it in the working directory. Alternately, it can drop you into a view of the diff in the editor, and you can add or modify diff lines as you please.

Honestly though, if you're doing that you should be using two different branches. Which is another thing git is wonderful for.
Yes, you are; SVN doesn't allow you to commit parts of a file -- it works at the file level. Git allows you to commit an arbitrary subset of changed lines from whatever files you've changed in your working copy. It doesn't track changes to files, it tracks changes to content in its tree. See here for a more complete explanation: https://git.wiki.kernel.org/index.php/GitFaq#Why_is_.22git_c...
> Am I missing something?

Yes. In git you can also do 'git add -p', which lets you interactively add pieces of a diff to the index, not just entire files.

Now, you could imagine an interface where you interactively select the pieces of the diff when committing, and I believe some VCSs do this. So, even though you were missing something, you weren't necessarily wrong. :)

But having the index can be useful if you want to build up the things you're going to commit over separate 'git add -p' sessions.

> Now, you could imagine an interface where you interactively select the pieces of the diff when committing

There's no need to imagine -- git-gui and git-cola can do this.

http://cola.tuxfamily.org/

Click on a modified file, select specific lines from the diff, right-click, and click on "stage selected lines".