For git, how to stage all the changes, including deletion, in a sub-directory by one command?

git

Solution

You can use the `-u` option to `git add` to do this, for example:

git add -u -- name-of-subdirectory

The documentation for `-u` says:

Only match <filepattern> against already tracked files in the index rather than the working tree. That means that it will never stage new files, but that it will stage modified new contents of tracked files and that it will remove files from the index if the corresponding files in the working tree have been removed.

If you also wanted to add new, untracked files, you could use `-A` instead of `-u`.

Problem

We know that `git add .` can stage all the new files or changes at once. But if you delete files directly by `rm command`, `git add .` will not stage these modification. Is there a efficient command to stage all the changes including deletion in a sub-directory?

Original source