Why is there a staging process in git?

This is a pure PITA (in my humble opinion). Evidently, most UI tools (actually all I know off, including Eclipse's EGit, Mac XCode, and GitHub client) don't expose this feature.

I understand the notion of partial commit. You don't want to commit everything you have on your file system. But introducing the concept of a "Stage" for it is an overkill.

There are currently 4 stages for your check-in to go through:

1. Your file system
2. The staging
3. your local repository
4. the remote upstream

UI frontends to git do not exposes the staging. They show you all the changes you have. You check the ones that you want to commit and you commit in a single operation.

Possibly, this is an impolmentation detail that got elevated into a UI concept. Instead of a:

commit( X, Y, Z)

you have:

add(X), add(Y), add(Z), commit()

  1. git commit doesn't have to check every file in the tree to see if has changed. On a big tree that can be a big time saving.
  2. By staging some files (or ever some changes within some files) you get nice fine grained control of what exactly you want to commit and what you do not. For instance, if you spot a trivial bug while part way through a big change you can quickly stage and commit a one line bug fix without all the other changes getting in the way.

The truth is: the index is a staging area. Every SCM has it, but git shows it to you, and uses it effectively.

One main reason is so you don't have to commit your entire working directory. You can move portions of it to the index and commit just those.

For example, you're working on two different things, and now your code looks like

//random code

//bug fix

//new feature

You can stage just the //bug fix line and commit that, and than stage the //new feature line and commit that.

You now have two different commits for each. Later on in testing you realize the new feature commit broke something, you can delete the new feature commit, but don't have to recommit the bugfix

As Dickon Reed noted in his answer, you also gain performance as git commit now only needs to add what is in the index to the commit. It doesn't need to search through your tree to find all the changes.


You might want to commit only some of your changes. If you fix something you can commit only the relevant changes for the fix.

Tags:

Git