{"thread":{"id":"64813","subject":"Repost: Inconsistent Behavior in 'git add' (git 2.52.0)?","startedAt":"2026-01-15T16:36:51Z","lastAt":"2026-01-18T17:50:31Z","messageCount":3,"participants":["Jon Forrest","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"533971","messageId":"12239ac3-bc9c-4484-8633-a255a706011c@gmail.com","threadId":"64813","inReplyTo":null,"subject":"Repost: Inconsistent Behavior in 'git add' (git 2.52.0)?","fromName":"Jon Forrest","fromEmail":"nobozo@gmail.com","sentAt":"2026-01-15T16:36:49Z","receivedAt":"2026-01-15T16:36:51Z","isPatch":false,"sender":{"key":"nobozo@gmail.com","avatar":"https://gravatar.com/avatar/37c6a7b57f29b3f35c6a9016537907c52f15bbf98575617dc046bcec6bf06372?d=mp&s=160"},"body":"Any response to this?\n\nShould I submit it in a bug report even though it's\nprobably not a bug?\n\nThanks,\nJon\n\n---\n\nA while back (6 Sep 2025) I submitted a report about how running\n\n     git 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"},{"id":"533972","messageId":"xmqq8qdydddl.fsf@gitster.g","threadId":"64813","inReplyTo":"12239ac3-bc9c-4484-8633-a255a706011c@gmail.com","subject":"Re: Repost: Inconsistent Behavior in 'git add' (git 2.52.0)?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-01-15T16:55:34Z","receivedAt":"2026-01-15T16:55:38Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jon Forrest <nobozo@gmail.com> writes:\n\n> % git init\n> Initialized empty Git repository in /tmp/fish/.git/\n>\n> The index is empty, as shown by\n> % git ls-files --cached\n> %\n>\n> I then ran\n>\n> % git add file1 jon\n> git add file1 jon\n> The following paths are ignored by one of your .gitignore files:\n> file1\n>\n> Again, this is exactly what I expected. But, running\n> '% git ls-files --cached' shows\n>\n> jon\n>\n> This is *not* what I expected.\n\nIf the exclude mechanism does not allow others to go through when it\nkicks in, like \"file1 is listed in .gitignore, so it should not be\nadded unless it is forced\", it would make it almost useless.\nImagine running \"git add .\" instead of running \"git add file1 jon\"\nand seeing that nothing gets added?\n\nIt is plausible to teach \"git add\" to treat paths that are\nexplicitly named on the command line (as opposed to the paths that\nare discovered due to recursion) differently, but that would be a\nnew feature, not a bugfix, I would think.\n\nEven then, I am not sure how useful it would be.  Imagine running\n\"git add *\" instead of \"git add .\" or \"git add file1 jon\" and seeing\nthat nothing gets added?  Unlike \"giving a '.' would let 'git add'\ndiscover 'file1' and 'jon' due to recursion\", an asterisk on the\ncommand line that is not quoted is expanded by the shell command\ninterpreter, and by the time 'git add' sees the parameters given to\nit, it cannot tell if 'file1' was explicitly typed or expanded via\n'*'.  It would be mildly irritating if the addition is rejected.\n\nSo, I dunno.\n\n\n"},{"id":"534147","messageId":"c51367f1-9ce2-4580-9f7c-4b1adc989582@gmail.com","threadId":"64813","inReplyTo":"xmqq8qdydddl.fsf@gitster.g","subject":"Re: Repost: Inconsistent Behavior in 'git add' (git 2.52.0)?","fromName":"Jon Forrest","fromEmail":"nobozo@gmail.com","sentAt":"2026-01-18T17:50:27Z","receivedAt":"2026-01-18T17:50:31Z","isPatch":false,"sender":{"key":"nobozo@gmail.com","avatar":"https://gravatar.com/avatar/37c6a7b57f29b3f35c6a9016537907c52f15bbf98575617dc046bcec6bf06372?d=mp&s=160"},"body":"Thanks for your response. This is indeed a very minor issue.\n\nOn 1/15/26 8:55 AM, Junio C Hamano wrote:\n\n> It is plausible to teach \"git add\" to treat paths that are\n> explicitly named on the command line (as opposed to the paths that\n> are discovered due to recursion) differently, but that would be a\n> new feature, not a bugfix, I would think.\n\nAgreed. I had been thinking of 'git add' as a kind of\ndatabase transaction, where either everything happens,\nor nothing happens.\n\nAn excluded file isn't considered the same type of\nerror as an invalid file, which is fine as long as\na user is aware of this behavior. The fact that\n'git add' warns about ignored files helps.\n\nAgain, this is a tiny, tiny issue.\n\nCordially,\nJon Forrest\n\n"}]}