如何将所有文件添加到其文件路径在文件中给出的阶段

How to add all files to stage whose file path is given in a file

假设我有一个文件files_to_stage.txt,其文件路径类似于

src/a/a1.txt
src/a/a2.txt
src/b/b3.txt
src/b/b6.txt
src/c/c5.txt

现在我想暂存所有路径在 files_to_stage.txt 中的文件,例如 src/a/a1.txt, src/a/a2.txt

我该怎么做?我正在寻找类似

的东西
git add -f files_to_stage.txt
git add $(cat files_to_stage.txt)

应该够了。

子命令($() 构造)读出您的文件并将其发送到 git add