Should I add deleted files to stage area?
I’m confused about Git.
I know that changed files or new files must be added to stage area, but what about deleted files? Should I add deleted files to the staging area too?
Here is a hypothetical scenario:
If I remove/delete
controller_1.php from my
myproject-dir/app/controller/, should I add this file to next commit?
One Solution collect form web for “Should I add deleted files to stage area?”
You should think about the staging area more as something were you add changes to. So adding a file to the repository is a change where you add a file. Modifying a file in the repository is a change where you modify a file. And deleting a file from the repository is a change where you delete the file.
So yes, for the repository to recognize that the file is actually removed from the repository in a commit, you need to add the file removal to the index.
You can do that using
git rm path/to/file
If you—for whatever reason—want to keep the file on the disk when removing it from the repository, you can use the
--cached option to keep it.
git rm --cached path/to/file
If the file is already physically deleted from the disk, you can still use
git rm as above to add the removal to the index. You can also use the update capability of
git add to discover updates to tracked files automatically and stage them:
git add -u .
This will add all changes (additions, modifications and file removals) of all tracked files in the current directory. If you leave off the dot at the end, it applies to the whole repository (so you have less control over it).