git/list[1] front-page[2] threads[3] people[4] search[5] about
 

committing selected 'changed' or 'added' files works, but not 'removed'

From
Jim Meyering <jim@meyering.net>
Date
May 14, 2007, 06:16 UTC
Message-ID
<87y7jsgcag.fsf@rho.meyering.net>
Hello,

If I've just run "git-rm -f c" in a directory with a few modified or git-added files, is there some way to commit (non-interactively) only the removal of that selected file? I.e., not any other changes in the working directory? git-commit -m. -- c fails with this:

  error: pathspec 'c' did not match any file(s) known to git
If I use "cg-commit" instead of "git-commit", it works fine.

When I asked on IRC, "cehteh" suggested to create a temporary branch, do the removal there, and then to rebase that change back onto the original branch -- and to remove the disposable branch. Yes, that works, but I want do the job with a single commit command, the same way I can for "added" and "modified" files. And I've been trying (until now, successfully) to wean myself away from cogito.

Why should "removed" files be handled so differently? If I cannot commit a selected "file removal" (regardless of the state of the index), then isn't that an opportunity to add a feature?

In case you're wondering, I want this functionality in order to make a version control agnostic commit/diff/ChangeLog tool work the same way with raw git as it did using cogito.

------------------------------------------- In case an actual scenario helps, I'd like to be able to commit the removal of "c", below without also committing the change to "b":

mkdir .j && cd .j && git-init > /dev/null && touch b c && git-add b c \
  && git-commit -q -m. && echo > b && git-rm --quiet -f c \
  && git-commit -m. -- c
The final commit above fails like this:
  error: pathspec 'c' did not match any file(s) known to git.
  Did you forget to 'git add'?
Next: Junio C Hamano
Message 1 of 3 in “committing selected 'changed' or 'added' files works, but not 'removed'”
  1. Jim MeyeringMay 14, 2007
  2. Junio C HamanoMay 14, 2007
  3. Jim MeyeringMay 14, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.