'How to re-add added files (update staged files only) in git?

We have modified files in path/to/another/ and path/to/main/.
Files in path/to/main/ already added into git cache but we have updated path/to/main/Bar.php file AGAIN. We now have the following situation:

$ git status
[...]
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   path/to/main/Foo.php
        modified:   path/to/main/Bar.php

Changes not staged for commit:
    (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   path/to/main/Bar.php
        modified:   path/to/another/Aaa.php
        modified:   path/to/another/Bbb.php

(note that path/to/main/Bar.php shows up twice)

I need a command which could readd files which were added before without using particular paths.

P.S. git add --update will add all these files. It doesn't work.

P.P.S. This command should be able to readd modified: and new file: types.

UPD1

Thanks to @AyonNahiyan, yeah, it can work in bash. But maybe there is a command without using bash tricks (subcommands).



Solution 1:[1]

git update-index can be used for this purpose.

In particular,

git update-index --again

should work.

The --again option selects the files already in index that are different from HEAD.

And the actual action of update-index is to pull into index the new contents of those files.

Solution 2:[2]

git update-index --again

will do what you want. Note that this command operates on the current working directory (and subdirectories, recursively) by default. If you want to apply the command to the whole repo, add a pathspec:

git update-index --again :/:

:/: here means "the root of the working tree".

P.S. you can add an alias for this command to your .gitconfig file, e.g.:

[alias]
    readd = update-index --again :/:

Solution 3:[3]

The answer from Ayon works. A possible fix for deleted files is to add another parameter.

--diff-filter=d

This excludes all deleted files from "git add". Further information on how to use this parameter can be found on this thread: Filter git diff by type of change

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eugene Yarmash
Solution 2
Solution 3 Sebastian Trauth