Kirby Kirby - 2 months ago 8
Git Question

How to readd 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 still updated
path/to/main/Bar.php
file.

$ 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


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.

Answer

This shows list of files that are only staged:

git diff --name-only --cached

Now stage these files with their new changes(It will work in bash)

git add $(git diff --name-only --cached)