Reputation: 195
According to the official git web site:
There are 4 states of files for git. So the question is: what status have deleted and moved/renamed files? Of course if the file is left in file system then after commit it will be untracked but before commit it has deleted status (for deletion). I think deletion is not really a file modification but an event.
Upvotes: 1
Views: 1552
Reputation: 78673
You can consider a delete or a rename exactly like an edit in this diagram. It doesn't matter if you're making a content change (editing the file), making a metadata change (setting the file executable, for example) or deleting it, it goes through the same workflow.
If you have a file committed to git (in the teal "unmodified" state in your diagram) and you delete it, you are now in the "modified" state. git has detected this change:
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: foo.txt
no changes added to commit (use "git add" and/or "git commit -a")
At this point the file is removed on-disk but not staged for deletion. It's in the yellow "modified" state. To stage it, you can stage it just like any other change, by running git add foo.txt
.
Recall, despite the name, git add
doesn't add a file, it stages the change to a file. In this case, the change is a delete, so git add
will stage a delete.
(I mention this only to prove a point, in fact, it's much more natural to run git rm
to stage a file's removal. Either will work.)
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: foo.txt
At this point, the file is in the red "staged" state. When you commit this change, the file will no longer exist in the repository.
[master 3b58d71] deleted
1 file changed, 7 deletions(-)
delete mode 100644 foo.txt
Recreating the file will start over in the grey "untracked" state.
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
foo.txt
nothing added to commit but untracked files present (use "git add" to track)
Upvotes: 1