{"thread":{"id":"64722","subject":"Inconsistent Behavior in 'git add' (git 2.52.0)","startedAt":"2026-01-04T19:33:19Z","lastAt":"2026-01-04T19:33:19Z","messageCount":1,"participants":["Jon Forrest"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"532997","messageId":"292537bb-e903-4baa-929c-6ffd0bf55a8e@gmail.com","threadId":"64722","inReplyTo":null,"subject":"Inconsistent Behavior in 'git add' (git 2.52.0)","fromName":"Jon Forrest","fromEmail":"nobozo@gmail.com","sentAt":"2026-01-04T19:33:17Z","receivedAt":"2026-01-04T19:33:19Z","isPatch":false,"sender":{"key":"nobozo@gmail.com","avatar":"https://gravatar.com/avatar/37c6a7b57f29b3f35c6a9016537907c52f15bbf98575617dc046bcec6bf06372?d=mp&s=160"},"body":"A while back (6 Sep 2025) I submitted a report about how running\n\n\tgit add x bogus_file\n\nwhere 'x' exists but 'bogus_file' doesn't results\nin 'x' not being added to the index. Peff was kind\nenough to explain that the presence of even 1 invalid file invalidates\nthe whole 'git add' command, no matter how many valid files\nare included. OK, fine.\n\nThis morning I was experimenting with what happens if a file\nis specified on a 'git add' command line where the file exists\nbut is in a .gitignore file. I was expecting the same behavior\nas when the file doesn't exist at all. Here's what happened:\n\n% ls -l file1 jon\n-rw-r--r-- 1 jonf 15 Dec 30 15:36 file1\n-rw-r--r-- 1 jonf  0 Jan  4 11:19 jon\n\n% git check-ignore -v file1\n.gitignore:2:file1      file1\n\nSo far, so good. Both file1 and jon exist, but file1 is\nin .gitignore. Just for yuks, I start with a clean repo.\n\n% git init\nInitialized empty Git repository in /tmp/fish/.git/\n\nThe index is empty, as shown by\n% git ls-files --cached\n%\n\nI then ran\n\n% git add file1 jon\ngit add file1 jon\nThe following paths are ignored by one of your .gitignore files:\nfile1\n\nAgain, this is exactly what I expected. But, running\n'% git ls-files --cached' shows\n\njon\n\nThis is *not* what I expected. I expected the 'git add' command to\nnot add anything to the index, the same way it behaved when I tried\nto add a file that doesn't exist (see the beginning of this message).\nBut, apparently specifying a missing file is considered a different\nkind of error than specifying an ignored file.\n\nOnce again, I'm wondering if this is expected behavior.\n\nCordially,\nJon Forrest\n\n\n\n\n\n\n\n\n\n\n"}]}