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?

  • Disable push to specific branches on GitHub
  • How to join last N merge commits into one?
  • Git merge commits from a specific upstream release
  • A “Git” like workflow using Subversion?
  • Sharing git repo on NTFS partition between Linux/Windows dualboot
  • Create public fork of private code, with private pushing changes to the public
  • Here is a hypothetical scenario:

    myproject-dir/app/contorller/controller_1.php
    myproject-dir/app/contorller/controller_2.php
    

    If I remove/delete controller_1.php from my myproject-dir/app/controller/, should I add this file to next commit?

  • What's the difference between ~ and ^ in git
  • How to resolve ALL conflicts using HEAD, with any mergetool
  • Using git commit -a with vim
  • How do I pull files from remote without overwriting local files?
  • Use gruntjs as precommit hook
  • How to commit a git repo into a git repo (not submodule)
  • 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:

    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).

    Git Baby is a git and github fan, let's start git clone.