Development Tools Introduction to Git Managing Committed Files Removing Files

Amandeep Pasricha
Amandeep Pasricha
14,929 Points

I still don't understand why a deleted file is not sent to the stages for commit?

Again, as the questions asks. I don't get his explanation.

2 Answers

Jamie Reardon
Jamie Reardon
Treehouse Project Reviewer

Only modified files go to the staging area, via the git add subcommand. When you make changes to a file, it's "modified". Therefore, when you add them via the git add subcommand, you are adding them to the staging area/cache.

When using the git rm or mv subcommands, they will go straight to the changes to be committed section.

Amandeep Pasricha
Amandeep Pasricha
14,929 Points

Oh okay, deleting a file does not count as modifying it. Therefore it skips that step and goes straight to the committed section, correct?

Jamie Reardon
Jamie Reardon
Treehouse Project Reviewer

Yes that is correct Amandeep. Like I said, only "modified"/new files go to the staging area, via the git add subcommand. Deleted and moved files are not counted as modified.

  • git add (staging area process and commit process)
  • git rm and git mv (commit process)

You can review this whole process on an earlier video in the first stage of this course, "First Commits". I have almost finished this course and I have been making notes on most of the videos :)

Tiago Ferrão
Tiago Ferrão
10,871 Points

however i tried git add . and the file shows on the

rm git.html ➜ temp_git git:(master) ✗ git status On branch master Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) deleted: git.html no changes added to commit (use "git add" and/or "git commit -a")

➜ temp_git git:(master) ✗ git add . ➜ temp_git git:(master) ✗ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage)

deleted:    git.html

considering the above, what is the difference between git rm or git add ?