Git Commands Recap : Add, rm, commit, diff

Git Add : git add <file_name1>,<file_name2>

If a file need to be committed to repo, it needs to be brought first to staging area(staging index) from working directory. The "git add" command is used to move files from working directory to staging index(Changes need to be committed area). Here we create three files and use git add command to move it in staged which can be verified using git status command.

➜  custom_cloned_repo git:(master) ✗ git add index.jsp
➜  custom_cloned_repo git:(master) ✗ git add .

git add command expects argument(s) - Either list of files names separated by comma or period(.) - all the files in working directory.

How to remove file from staged area(To un-stage) :
Using "git rm --cached <file_name>" - file can be moved from staged index to working area(un-stage). Below rm command un-stage front.css and move to untracked section .
➜  custom_cloned_repo git:(master) ✗ git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

 new file:   front.css
 new file:   front.js
 new file:   index.jsp

➜  custom_cloned_repo git:(master) ✗ git rm --cached front.css 
rm 'front.css'
➜  custom_cloned_repo git:(master) ✗ git status               
On branch master
Your branch is up-to-date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

 new file:   front.js
 new file:   index.jsp

Untracked files:
  (use "git add <file>..." to include in what will be committed)


Git Commit : git commit /git commit -m "<commit_message>"

The git commit command takes files from the Staging Index and saves them in the repository. "git commit" opens configured editor for capturing commit message, if not configured vim will be used as default editor.
Command "git config --list" displays git configuration, Refer this for associating text editor with git.

git commit with -m flag is used to specify comments inline(default editor do not open for capturing commit message).
➜  custom_cloned_repo git:(master) ✗ git commit -m "added js and index jsp"
[master 67d8efc] added js and index jsp
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 front.js
 create mode 100644 index.jsp

Git Diff : git diff

git status tell us what files have been changed, but does not conveys what those changes are.The git diff command is used to find out what those changes are.

The git diff command can be used to see changes that have been made but haven't been committed, yet. It also displays:

  • the files that have been modified
  • the location of the lines that have been added/removed
  • the actual changes that have been made

Note: Outcome of "git log -p" is similar to "git diff".


  1. Replies
    1. Great Article
      Cloud Computing Projects

      Networking Projects

      Final Year Projects for CSE

      JavaScript Training in Chennai

      JavaScript Training in Chennai

      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

  2. I have been reading for the past two days about your blogs and topics, still on fetching! Wondering about your words on each line was massively effective. Techno-based information has been fetched in each of your topics. Sure it will enhance and fill the queries of the public needs. Feeling so glad about your article. Thanks…!
    magento training course in chennai
    magento training institute in chennai
    magento 2 training in chennai
    magento development training
    magento 2 course
    magento developer training

Previous Post Next Post