Why is there the staging area between “git add” and “git commit”?
I understand the concept, but fail to see the sense in adding files to the staging area before actually commiting. Why not skip this step?
Why is there the staging area between git add and git commit? I understand
Share
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
You can stage just the
//bug fixline and commit that, and than stage the//new featureline and commit that.You now have two different commits for each. Later on in testing you realize the
new featurecommit broke something, you can delete thenew featurecommit, but don’t have to recommit the bugfixAs Dickon Reed noted in his answer, you also gain performance as
git commitnow 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.