![](https://s3.amazonaws.com/media-p.slid.es/uploads/173331/images/2921193/git.png)
GiT
The index
or staging, or cache
The index
What is it?
The Index is your proposed next commit
https://git-scm.com/
![](https://s3.amazonaws.com/media-p.slid.es/uploads/173331/images/2920176/git-staging-workflow1.png)
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
![](https://s3.amazonaws.com/media-p.slid.es/uploads/173331/images/2920235/Screen_Shot_2016-08-16_at_16.26.15.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/173331/images/2920225/git-staging-workflow2.png)
The index
How to see changes?
git diff
git diff --cached
git diff --staged
![](https://s3.amazonaws.com/media-p.slid.es/uploads/173331/images/2920228/git-staging-workflow3.png)
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
![](https://s3.amazonaws.com/media-p.slid.es/uploads/173331/images/2922286/Screen_Shot_2016-08-17_at_10.00.02.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/173331/images/2924921/Screenshot_from_2016-08-18_07-33-10.png)
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
- 778