Committing files in Git

Three states of files in git

at any point of time a file in git can be in 1 of the following three states
modified a file is just modified.You have changed the contents of the file but the file is not stored in the database.
staged file is modified and you have marked it as to be committed.when you perform commit the next time then the file will be committed.
committed this means that the contents of the file are safely stored in the git database.

There are 2 main concepts to remember when working with git:

  • Working directory   This represents a specific version of the files.You work with working directory and modify and commit files in the working directory.
  • Repository   This stores all the versions of all the files which are managed by git.Repository resides in the .git subdirectory in the working directory.

Checking status of file or directory in git

to check the status of files of a git repository use the following command:

This will list all the files which have been modified since the last commit.

In the following screen shot below none of the files have been modified since the last commit

check-staus-of-files-in-git
In the following screenshot 2 files were modified since the last commit

check-status-of-files-in-git-modified-files

Now we add one of the files to the staging area as:

If we run the git status command now we can see that one of the files has been staged.

check-status-of-files-in-git-staged-files
Now we commit the staged files using the following command:
$ git commit -m “initial commit”

commit-file-in-git

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *