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

Git add on deleted file

From
Angus Hammond <angusgh@gmail.com>
Date
Aug 13, 2012, 17:34 UTC
Message-ID
<CAOBOgRZRSk7+jxMg+v=GWcn3F9ZfDTGC89YhJ1s7o9=HaOx4Bg@mail.gmail.com>

I was messing around with git add and how it interacts with deleted files earlier today and came across this odd behavior.

$git init
Initialized empty Git repository in /tmp/test/.git/
$touch foo
$git add foo
$git commit -m"initial commit"
[master (root-commit) 0b5a193] initial commit
 0 files changed
 create mode 100644 foo
$rm foo
$git status
# On branch master
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    foo
#
no changes added to commit (use "git add" and/or "git commit -a")
$git add foo
$git status
# On branch master
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    foo
#
no changes added to commit (use "git add" and/or "git commit -a")

Notice that the two outputs from git status are identical, so git add doesn't appear to have changed anything. Personally I'd like to see "git add foo" here be equivalent "git rm --cached foo", but I can understand how others might prefer git add not to be destructive like that. Either way, I don't think it's right that the command exits without any output (which would normally indicate success) yet has failed to do anything. Perhaps it should act more like git add does when the file doesn't exist in the working directory or the index:

$git add bar fatal: pathspec 'bar' did not match any files

Thanks Angus

Next: Junio C Hamano
Message 1 of 3 in “Git add on deleted file”
  1. Angus HammondAug 13, 2012
  2. Junio C HamanoAug 13, 2012
  3. Ralf ThielowAug 13, 2012

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.