{"thread":{"id":"49083","subject":"What's the use case for committing both the freshly created file and it's exclusion in .gitignore?","startedAt":"2018-08-09T11:04:48Z","lastAt":"2018-08-10T21:56:35Z","messageCount":5,"participants":["Bartosz Konikiewicz","Jeff King","Jonathan Nieder","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"354984","messageId":"CAAdU=LuNn7qdXf81C3-3=0uh7NOSihm3U3dfDcXPiKxfaZMaFQ@mail.gmail.com","threadId":"49083","inReplyTo":null,"subject":"What's the use case for committing both the freshly created file and it's exclusion in .gitignore?","fromName":"Bartosz Konikiewicz","fromEmail":"izdwuut@gmail.com","sentAt":"2018-08-09T11:04:43Z","receivedAt":"2018-08-09T11:04:48Z","isPatch":false,"sender":{"key":"izdwuut@gmail.com","avatar":null},"body":"Hi there!\n\nI hope that the subject of my message (i.e. the question) is\nexhaustive enough, so I'll just stick to reproducing my issue.\n\nSteps to reproduce:\n\n1. Create a new file.\n2. Stage the file.\n3. Add the file to .gitignore.\n4. Stage the .gitignore.\n5. Commit changes.\n\nI imagined that the file would now be removed from the stage (because\nit's ignored now and not yet committed) but it isn't. Where this\nbehavior would be desirable? I know that a 'git add' command can be\ninvoked with an '-f' flag, which would yield the same result, but I\ncan't come up with an explanation where can it be applied.\n"},{"id":"355032","messageId":"20180809195845.GE32376@sigill.intra.peff.net","threadId":"49083","inReplyTo":"CAAdU=LuNn7qdXf81C3-3=0uh7NOSihm3U3dfDcXPiKxfaZMaFQ@mail.gmail.com","subject":"Re: What's the use case for committing both the freshly created file and it's exclusion in .gitignore?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-08-09T19:58:45Z","receivedAt":"2018-08-09T19:58:48Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Aug 09, 2018 at 01:04:43PM +0200, Bartosz Konikiewicz wrote:\n\n> Hi there!\n> \n> I hope that the subject of my message (i.e. the question) is\n> exhaustive enough, so I'll just stick to reproducing my issue.\n> \n> Steps to reproduce:\n> \n> 1. Create a new file.\n> 2. Stage the file.\n> 3. Add the file to .gitignore.\n> 4. Stage the .gitignore.\n> 5. Commit changes.\n> \n> I imagined that the file would now be removed from the stage (because\n> it's ignored now and not yet committed) but it isn't. Where this\n> behavior would be desirable? I know that a 'git add' command can be\n> invoked with an '-f' flag, which would yield the same result, but I\n> can't come up with an explanation where can it be applied.\n\nAs far as I know, that is not an intentionally supported workflow. It is\nmerely the result that .gitignore is only considered when adding new\nfiles to the index, not when committing nor when updating the entry for\nan existing file.\n\nIf you are asking as a more general case: why do we not complain about\n.gitignore for files the index already knows about, then I think that is\nuseful. It lets you override the .gitignore _once_ when adding the file\ninitially, and then you don't have to deal with it again (and keep in\nmind that the pattern excluding it may be broad, like \"*.o\", or even\njust \"*\", so simply deleting it from the .gitignore is not an option).\n\nYou could probably accomplish this these days by using a negative\npattern in your .gitignore file. But I think the behavior in question\nmay predate negative patterns (but I didn't dig). It's also a bit\nsimpler to use in practice, IMHO.\n\n-Peff\n"},{"id":"355073","messageId":"20180810011249.GA82458@aiede.svl.corp.google.com","threadId":"49083","inReplyTo":"20180809195845.GE32376@sigill.intra.peff.net","subject":"Re: What's the use case for committing both the freshly created file and it's exclusion in .gitignore?","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2018-08-10T01:12:49Z","receivedAt":"2018-08-10T01:12:55Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nJeff King wrote:\n> Bartosz Konikiewicz wrote:\n\n>> Steps to reproduce:\n>>\n>> 1. Create a new file.\n>> 2. Stage the file.\n>> 3. Add the file to .gitignore.\n>> 4. Stage the .gitignore.\n>> 5. Commit changes.\n[...]\n> As far as I know, that is not an intentionally supported workflow. It is\n> merely the result that .gitignore is only considered when adding new\n> files to the index, not when committing nor when updating the entry for\n> an existing file.\n\nI am not sure I agree with \"not intentionally supported\".  It's a\nlittle closer to \"logical consequence of some intentionally features\",\nbecause:\n\n> If you are asking as a more general case: why do we not complain about\n> .gitignore for files the index already knows about, then I think that is\n> useful. It lets you override the .gitignore _once_ when adding the file\n> initially, and then you don't have to deal with it again (and keep in\n> mind that the pattern excluding it may be broad, like \"*.o\", or even\n> just \"*\", so simply deleting it from the .gitignore is not an option).\n\nThis workflow is very common.\n\n> You could probably accomplish this these days by using a negative\n> pattern in your .gitignore file. But I think the behavior in question\n> may predate negative patterns (but I didn't dig). It's also a bit\n> simpler to use in practice, IMHO.\n\nAgreed about simpler, even though it's not part of any of my own\nhabits.\n\nIn retrospect, despite the precedent of cvsignore, calling the file\n.gitignore may not have been a great idea.  Some other name that\nconveys .git-prevent-me-from-accidentally-adding-these-files would\nmake the behavior less surprising to new users.\n\n\"git help gitignore\" has some notes about this.  If you have ideas\nabout moments in interactive use where we could print some messages to\nmake the behavior less surprising, that would be very welcome.\n\nThanks,\nJonathan\n"},{"id":"355077","messageId":"CAAdU=LuXh6jo+pDPE-tisd_SoMhGjGL6kvm6X91Qsz1-XYD0wA@mail.gmail.com","threadId":"49083","inReplyTo":"20180810011249.GA82458@aiede.svl.corp.google.com","subject":"Re: What's the use case for committing both the freshly created file and it's exclusion in .gitignore?","fromName":"Bartosz Konikiewicz","fromEmail":"izdwuut@gmail.com","sentAt":"2018-08-10T10:19:08Z","receivedAt":"2018-08-10T10:19:13Z","isPatch":false,"sender":{"key":"izdwuut@gmail.com","avatar":null},"body":"On 9 August 2018 at 21:58, Jeff King <peff@peff.net> wrote:\n> If you are asking as a more general case: why do we not complain about\n> .gitignore for files the index already knows about, then I think that is\n> useful. It lets you override the .gitignore _once_ when adding the file\n> initially, and then you don't have to deal with it again (and keep in\n> mind that the pattern excluding it may be broad, like \"*.o\", or even\n> just \"*\", so simply deleting it from the .gitignore is not an option).\n\nThis totally makes sense to me. Thanks for your explaination!\n\nOn 10 August 2018 at 03:12, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> \"git help gitignore\" has some notes about this.\n\nThanks! I wasn't aware of this. For some peculiar reason it didn't\nstrike me that the most appropriate place to look for\n.gitignore-related stuff is - lo and behold - .gitignore manual page.\nI was looking for clarification on 'git add' page, which I didn't find\ninformative enough in that aspect.\n\n> If you have ideas\n> about moments in interactive use where we could print some messages to\n> make the behavior less surprising, that would be very welcome.\n\nSure I do! I have came up with two ideas which I believe that can be combined:\n\n1.\n>            staged     unstaged path\n>   1:    unchanged        +1/-0 .gitignore !\n>   2:        +0/-0      nothing excluded.txt\n>\n> ! Not ignoring yet untracked files.\n>\n> *** Commands ***\n>   1: status       2: update       3: revert       4: add untracked\n>   5: patch        6: diff         7: quit         8: help\n> What now>\n\nHere I propose to add an exclamation mark next to a .gitignore file\nand reference it below. I am also thinking about marking files that\n.gitignore affects. I think that any special character would be\nappropriate. If I may only suggest, I wouldn't choose an asterisk (*)\nbecause it's already used when a '2: update' option is chosen.\n\n2.\n>            staged     unstaged path\n>   1:    unchanged        +1/-0 .gitignore\n>   2:        +0/-0      nothing excluded.txt\n>\n> *** Commands ***\n>   1: status       2: update       3: revert       4: add untracked\n>   5: patch        6: diff         7: quit         8: help\n> What now> q\n> You are about to add new files that are excluded in .gitignore. Confirm y/n?\n> What now>y\n> Bye.\n\nHere I ask the user to confirm that he is about to stage yet untracked\nfiles. Then I cheer him up with Git built-in courtesy.\n"},{"id":"355167","messageId":"20180810215626.GC70480@genre.crustytoothpaste.net","threadId":"49083","inReplyTo":"CAAdU=LuNn7qdXf81C3-3=0uh7NOSihm3U3dfDcXPiKxfaZMaFQ@mail.gmail.com","subject":"Re: What's the use case for committing both the freshly created file and it's exclusion in .gitignore?","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-08-10T21:56:27Z","receivedAt":"2018-08-10T21:56:35Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Thu, Aug 09, 2018 at 01:04:43PM +0200, Bartosz Konikiewicz wrote:\n> Steps to reproduce:\n> \n> 1. Create a new file.\n> 2. Stage the file.\n> 3. Add the file to .gitignore.\n> 4. Stage the .gitignore.\n> 5. Commit changes.\n> \n> I imagined that the file would now be removed from the stage (because\n> it's ignored now and not yet committed) but it isn't. Where this\n> behavior would be desirable? I know that a 'git add' command can be\n> invoked with an '-f' flag, which would yield the same result, but I\n> can't come up with an explanation where can it be applied.\n\nLet me give you one.  If you use pristine-tar to check in the contents\nof an upstream tarball, upstream may have included both a .gitignore\nfile and one or more ignored files in their tarball (say, something\nautoconf generated).  Both of those files will be required in order to\nreproduce the tarball, so git add -f or multiple stages of add will need\nto be used.\n\nIf we unstaged the files from the index when the .gitignore was added,\nthis workflow wouldn't be possible.\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"}]}