git 只提交修改过的文件作为原子提交,然后只提交删除的文件作为单独的原子提交

git commit only modified files as atomic commit, then commit only deleted files as separate atomic commit

我的 git staging 区域混合了 deletednewmodified 文件, 也就是说,它们已经全部 add 到暂存区,并准备好最终 commit 到存储库。

如何通过 'status' 而不是使用路径规范提交文件?

例如,我如何commit(来自staging区域)仅deleted的文件,但留下newmodified单独的文件,在暂存中?

原因是因为我想创建单独的原子提交,其中包含对正在提交的文件更 exact/applicable 的单独注释。

如果可能的话,我会:

  • 重置索引(不再有暂存文件)
  • 按状态添加它们,然后提交

您可以按状态添加(如 ):

git add --all $(git diff --diff-filter=D --name-only)

D 用于删除。使用 other filters,如 A 用于添加或 M 用于修改。