user24
user24

Reputation: 119

Could not get the difference between git staging area , working area

I am cofused with git states and correct me where i am wrong

Suppose i have 5 file A,B,C,D,E

D,E are new files , A,B i have changed, C remians same since last commit

Now from my understanding

  1. C is in Git directory or repository
  2. D,E are in working directory
  3. A,B now will they be in working directory becaus ethey were modified or they are in staged area

  4. When i do git commit without adding , then A,B goes to git directory or index

  5. if i do git add then D,E go to staged area

  6. Finally if i do git commit again then D,E go to git directory or index

Am i correct in my steps or i am understanding it wrong

Upvotes: 0

Views: 398

Answers (2)

Shyampal
Shyampal

Reputation: 79

--One can modify the existing file, create a new file and all these changes will be in the working directory. These changes will not be up for the commit. --Once the user stages the changes done in the working directory using the commands "git add ", those file will be in the staging area and will be available for the commmit. --If a user has add a file in the staging area and then modified file again, in that case only those changes which were present before the running the "git add" command will be available for the commit and not the new changes done after "git add" command. If user needs to incorporate the fresh modified changes, then file needs to add file again in the staging area using the "git add" command.

So difference between working area and staging area as evident is from upper reasoning is that only those changes are up for commit which are in the staging area and not the changes present in working area. User can do all the work, creating, editing, deleting and organizing files in the working area and when he needs to commit the modified files, it will be needs to bring those files in the staging area using "git add" commands and only those files will be made available for commit.

Upvotes: 1

Mad Physicist
Mad Physicist

Reputation: 114240

You always need to do an add before a commit. If you commit without making any changes, you will get a message like

# On branch master
nothing to commit, working directory clean

This means there is nothing in the staging area to commit.

When you add the current directory, the modifications to A, B will be added to the staging area, C will remain outside the staging area, and D, E get added in their entirety (since the whole file is a modification from the previous commit). Think of the staging area as the place you put all your changes before committing.

When you commit after adding, the latest version of your repository now contains updated versions of A, B as well as new files D, E. Git stores changes to a set of files rather than the files themselves. A "commit" is a snapshot of the changes that were made up to a point. The files can be reconstructed at any commit by applying the changes up to that commit in the order they were made in.

Upvotes: 2

Related Questions