Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Should I ignore the Index or is there a killer application for it?

Tags:

git

svn

As a subversion user, git's index is the most challenging new concept I'm facing as I consider using it for new projects. I read many people's comments saying that they don't use the Index (always commit -a) but I'm thinking there might be a killer reason out there as to why I would want to make use of it. (I'm sharing code with around 5 other developers, working in a mature development environment where we merge code to test and stable branches and use branching for experimental or significant new features.)

like image 544
Peter Howe Avatar asked Dec 03 '09 00:12

Peter Howe


1 Answers

You know that the index lets you only commit parts of the files that you want to add to the repository, of course. In general, I find it useful for this reason. I can make changes to files that sort of work, check in the parts that work, and then complete and check in the rest.

For a really killer demonstration; try using interactive add, or patch add (using git add -i, or git add -p). This runs through all your changes and lets you selectively add them to the index. This lets you make a whole load of changes to your files and yet split the commits. Useful for those 'aha' fixes that we all make from time to time.

Have a look at this screencast to see how it's done. Not till you try it yourself will you see how useful it is.

like image 95
Abizern Avatar answered Oct 18 '22 16:10

Abizern