gitversion-controlgit-index

Why does Git need to design Index /Stage?


The following image is Git flow diagram, I'm very strange why Git need to design Index /Stage.

You know the communication between Repository and Workspace is local, it's easy to commit or rollback between Repository and Workspace.

Why does Git need to design Index /Stage ?

Image

enter image description here


Solution

  • This is sort of a preview for changes about to be committed. You can, incrementally or in one go, constitute the future commit in this dedicated space, inspect what's in it, and commit only when you're satisfied with its contents.

    Some people almost ignore its existence and never use add, relying on -a for their commits to add everything blindly, but this is considered bad practice as it sets up future headaches when, in more complex cases, an understanding of the index will be crucial.

    I'd suggest looking at this, among other articles.