具有特定扩展名的暂存文件,并且仅显示在 git 状态下已修改的文件

Stage files with specific extension, and only those that show as modified in git status

在命令提示符的 git 中,我想简单地添加 *.cpp*.h 文件,但只有那些显示为已修改的文件,当我 运行 命令 git status.

例如,如果在我 运行 命令 git status 之后我得到:

未准备提交的更改:

未跟踪的文件:

然后我想暂存所有内容(所有 cpps 和 h 文件),除了最后两个。我怎么做?谢谢

git add-u 选项与您需要的任何其他选项结合使用:

-u
--update

Update the index just where it already has an entry matching <pathspec>. This removes as well as modifies index entries to match the working tree, but adds no new files.

在这种情况下,git add -u '*.cpp' '*.h' 应该可以满足您的要求。