Git builds new commits from whatever is in Git's index (aka staging-area).
If you remove a file from your working tree, but leave the copy of the file in the index, and then make a new commit, the new commit contains the file, because the file is there in Git's index. The file continues not to exist in your working tree, because committing does not update your working tree.
Note that running git add -u
or git add file
will remove the file from Git's index. The next commit will now lack the file, i.e., the difference between the current commit—which has the file—and the next commit will include "delete the given file". So it's always a question of what's in Git's index, not what's in your working tree, and from there, a question of "what does this Git command do to Git's index". Using git rm
removes the file from Git's index, but—rather peculiarly—so can git add
!