Table of content

Git Editing File

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 commandpwd, 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.

EF-cd-ls-starter-web

  • Next, modify the hipster.txt file, enter Notepad++ hipster.txt, it will take you to the editor page, now open hipster ipsum website and copy some dummy text over there and paste it into the editor page and then save and exit.
    EF-cprompt-notepad
  • Now give,git status you 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.
    EF-git-status

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 bygit 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.

  • If you do a,git status we still have the file hipster.txt which has not committed yet.
    EF-coomit-status

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.
EF-add-hipstertxt

  • Now, let us modify the hipster.txt file once again by adding dummy text somewhere in the middle and do 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.
    EF-onemoretime-editing-hipster
    EF-second-git-status
  • So now am going to add the modified file into the staging area using git add hipster.txt
  • If you do git status you can see both the files are in the staging area.
    EF-second-add-hipster
  • Let us commit the file git commit -m "more ipsum for hpsters" and press enter and then do git status you 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.
    EF-Second -commit-status

Git commit operation

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions