1

I have a mix of deleted, new and modified files in my git staging area, i.e. they are already all added to the staging area and are ready to be finally committed to the repository.

How do I commit file by 'status' instead of using a pathspec?

Example, how do I commit (from the staging area) only the files that have been deleted, but leave new and modified files alone, in staging?

The reason is because I want to create separate atomic commits with separate comments that are more exact/applicable to the files being committed.

skeetastax
  • 1,016
  • 8
  • 18

1 Answers1

2

If possible, I would:

  • reset the index (no more staged files)
  • add them by status, then commit

You can add by status (as shown here) with:

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

D is for deleted. Use other filters, like A for added or M for modified.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • `git reset ...` ? – skeetastax Feb 16 '21 at 23:20
  • 1
    @skeetastax yes, a simple `git reset` will empty the staging area, giving you the opportunity to add those files again, this time by status (deleted, added or modified). `git reset` alone (*not* `git reset --hard`, which would also reset the working tree, that is, your files) – VonC Feb 16 '21 at 23:33