Git Editing file involves the process of modifying a file which is in the staging area or in the working directory for multiple times, once you modified any files which are not committed yet, so we have to add that file to the staging area.
So the file which is staged is ready to commit and the changes are not staged, are not ready to commit.
Let us understand this process through a Demo as shown below:
Open Gitbash and check your home directory by passing command
pwd, here am using my project folder for all my projects, in that you can see starter-web-1/ folder then
cd into it hence you are directed to a starter-web-1 folder, now do
ls you will see all the files in that folder including our newfile.txt and hipstaer.txt.
git statusyou can see a return message, there will be a new file called newfile.txt which is already been staged so changes are ready to be committed.there is another one file called hipster.txt which is modified just now, hence the changes are not staged for commit.
Once again modify the hipster.txt file by adding some dummy text and save, exit.so it is just in my working directory now. what I can do is, I will commit the file by
git commit -m "adding new file", because the commit message only going to get the file from to be committed state, which is actually in the staging area.
git statuswe still have the file hipster.txt which has not committed yet.
We have to add the file to the staging area by using command
git add hipster.txt. The main point of the staging area is that, if we do not want to make any changes to that file again means we have to use -a parameter in the commit command.
If you do a,
git status now the hipster.txt file has moved to the staging area.
git status. even if you do it in the same also, Git can track the difference between changes that are to be committed, that is which are staged and the changes that have not been staged yet.
git add hipster.txt
git statusyou can see both the files are in the staging area.
git commit -m "more ipsum for hpsters"and press enter and then do
git statusyou can see that your working directory is clean, this means that there is nothing in the working directory and everything has moved to the staging area.