GiT
The index
or staging, or cache
The index
What is it?
The Index is your proposed next commit
https://git-scm.com/
The index
What is the point?
Isn't git commit -a enough?
The index
What is the point?
Prepare commits
Make sure they contain only what is needed
Separate commits per subtask/change
Prevents committing undesirable changes (debug, local configuration...)
The index
How to use it?
your new best friend:
git add
The index
How to see changes?
git diff
git diff --cached
git diff --staged
The index
Go forward
Git does not work with files, but with changes... And so do developers!
How to stage changes instead of files?
The index
Go forward
- Good practice to do small and atomic commit
- How to do so and add what we need only without disturbing the coding flow?
The index
git add --patch
git add --interactive
The reason why git add is your new best friend
Depending on the nature of a change, its impact and the way it is reviewed is different
- comment, indentation have no logical impact,
- refactor,
- bugfix,
- new feature,
- ...
Depending on the code, its impact and the way it is reviewed is different
Having different types of changes in a changeset makes it difficult to understand them properly
Is every committed changes what the developer wanted to commit (extra lines, debug, unused code...)?
The index
git add --patch
Pros:
- Makes commit cleaner
- The branch becomes easier to review and debug
- Having targeted commits adds some extra documentation with their message
- Makes the code being more reviewed
- Helps spotting unwanted changes
The index
git add --patch
Whatever we well understand we express clearly, and words flow with ease.
Nicolas Boileau-Despréaux
Questions?
References
- http://ghislain-rodrigues.fr/articles/git-add---interactive.html
- http://gitolite.com/uses-of-index.html
Git - The index
By Ghislain Rodrigues
Git - The index
- 801