{"thread":{"id":"49887","subject":"git overwriting local ignored files?","startedAt":"2018-11-24T02:55:14Z","lastAt":"2018-11-25T02:06:44Z","messageCount":6,"participants":["David Mandelberg","Junio C Hamano","Konstantin Khomoutov"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"363986","messageId":"a852c0e9-f278-8e2a-406c-bb6099b2440c@mandelberg.org","threadId":"49887","inReplyTo":null,"subject":"git overwriting local ignored files?","fromName":"David Mandelberg","fromEmail":"david@mandelberg.org","sentAt":"2018-11-24T02:35:05Z","receivedAt":"2018-11-24T02:55:14Z","isPatch":false,"sender":{"key":"david@mandelberg.org","avatar":"https://avatars.githubusercontent.com/u/15314936?v=4"},"body":"Hi,\n\nIt seems that git is overwriting my local files on merge if they're in \n.gitignore. See command transcript below. I searched `git help config` \nand Google, but I couldn't find any way to prevent it. Am I missing \nsomething? (The reason I care about ignored files is that I'm using git \nwith a working directory of $HOME to manage my dotfiles, and most files \nin my $HOME are not tracked by git but are still important.)\n\ndseomn@solaria:~$ mktemp -d\n/tmp/tmp.RHyyMxJ5Zp\ndseomn@solaria:~$ cd /tmp/tmp.RHyyMxJ5Zp\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp$ git init --bare repo.git\nInitialized empty Git repository in /tmp/tmp.RHyyMxJ5Zp/repo.git/\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp$ git clone repo.git foo\nCloning into 'foo'...\nwarning: You appear to have cloned an empty repository.\ndone.\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp$ git clone repo.git bar\nCloning into 'bar'...\nwarning: You appear to have cloned an empty repository.\ndone.\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp$ cd foo\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/foo (master)$ echo '*' > .gitignore\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/foo (master)$ git add -f .gitignore\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/foo (master)$ git commit -m 'gitignore'\n[master (root-commit) affd2fb] gitignore\n  1 file changed, 1 insertion(+)\n  create mode 100644 .gitignore\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/foo (master)$ git push\nCounting objects: 3, done.\nWriting objects: 100% (3/3), 216 bytes | 216.00 KiB/s, done.\nTotal 3 (delta 0), reused 0 (delta 0)\nTo /tmp/tmp.RHyyMxJ5Zp/repo.git\n  * [new branch]      master -> master\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/foo (master)$ cd ../bar\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/bar (master)$ git fetch\nremote: Counting objects: 3, done.\nremote: Total 3 (delta 0), reused 0 (delta 0)\nUnpacking objects: 100% (3/3), done.\n From /tmp/tmp.RHyyMxJ5Zp/repo\n  * [new branch]      master     -> origin/master\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/bar (master)$ git merge @{u}\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/bar (master)$ echo hi > quux\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/bar (master)$ git add -f quux\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/bar (master)$ git commit -m 'quux'\n[master aee4b54] quux\n  1 file changed, 1 insertion(+)\n  create mode 100644 quux\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/bar (master)$ git push\nCounting objects: 3, done.\nDelta compression using up to 4 threads.\nCompressing objects: 100% (2/2), done.\nWriting objects: 100% (3/3), 273 bytes | 273.00 KiB/s, done.\nTotal 3 (delta 0), reused 0 (delta 0)\nTo /tmp/tmp.RHyyMxJ5Zp/repo.git\n    affd2fb..aee4b54  master -> master\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/bar (master)$ cd ../foo\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/foo (master)$ echo bye > quux\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/foo (master)$ git fetch\nremote: Counting objects: 3, done.\nremote: Compressing objects: 100% (2/2), done.\nremote: Total 3 (delta 0), reused 0 (delta 0)\nUnpacking objects: 100% (3/3), done.\n From /tmp/tmp.RHyyMxJ5Zp/repo\n    affd2fb..aee4b54  master     -> origin/master\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/foo (master)$ cat quux\nbye\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/foo (master)$ git merge @{u}\nUpdating affd2fb..aee4b54\nFast-forward\n  quux | 1 +\n  1 file changed, 1 insertion(+)\n  create mode 100644 quux\ndseomn@solaria:/tmp/tmp.RHyyMxJ5Zp/foo (master)$ cat quux\nhi\n\n-- \nhttps://david.mandelberg.org/\n"},{"id":"363989","messageId":"xmqqftvr2jfo.fsf@gitster-ct.c.googlers.com","threadId":"49887","inReplyTo":"a852c0e9-f278-8e2a-406c-bb6099b2440c@mandelberg.org","subject":"Re: git overwriting local ignored files?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-11-24T04:22:51Z","receivedAt":"2018-11-24T04:23:17Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Mandelberg <david@mandelberg.org> writes:\n\n> It seems that git is overwriting my local files on merge if they're in\n> .gitignore. See command transcript below. I searched `git help config`\n> and Google, but I couldn't find any way to prevent it. Am I missing\n> something? (The reason I care about ignored files is that I'm using\n> git with a working directory of $HOME to manage my dotfiles, and most\n> files in my $HOME are not tracked by git but are still important.)\n\nThe .gitignore file is to list \"ignored and expendable\" class of\nfiles; there is no \"ignored but precious class\" in Git.\n"},{"id":"364004","messageId":"7ac49733-2e62-7d29-36aa-99df4124b54c@mandelberg.org","threadId":"49887","inReplyTo":"xmqqftvr2jfo.fsf@gitster-ct.c.googlers.com","subject":"Re: git overwriting local ignored files?","fromName":"David Mandelberg","fromEmail":"david@mandelberg.org","sentAt":"2018-11-24T14:37:06Z","receivedAt":"2018-11-24T14:37:13Z","isPatch":false,"sender":{"key":"david@mandelberg.org","avatar":"https://avatars.githubusercontent.com/u/15314936?v=4"},"body":"On 11/23/18 11:22 PM, Junio C Hamano wrote:\n> David Mandelberg <david@mandelberg.org> writes:\n> \n>> It seems that git is overwriting my local files on merge if they're in\n>> .gitignore. See command transcript below. I searched `git help config`\n>> and Google, but I couldn't find any way to prevent it. Am I missing\n>> something? (The reason I care about ignored files is that I'm using\n>> git with a working directory of $HOME to manage my dotfiles, and most\n>> files in my $HOME are not tracked by git but are still important.)\n> \n> The .gitignore file is to list \"ignored and expendable\" class of\n> files; there is no \"ignored but precious class\" in Git.\n\nOk. Would a patch be welcome? I have three ideas for how to implement \nit, and I'm not sure which is better.\n\n1. Add a boolean config option called core.preserveIgnore (or similar). \nI'm guessing this is the least amount of work, but it's not very \nflexible. I'm also not sure how it should work with `git clean`.\n\n2. Add some syntax to the .gitignore format so the same file can list \nboth \"ignored and expendable\" and \"ignored and precious\". I could see \nusing this to mark compiled files as ignored+expendable and per-repo \neditor/IDE config files as ignored+precious. Do you have any idea how \nbig of a patch this would be? Or any idea for the new syntax? I think \nstarting a line with \"\\x\" where x is any character not currently escaped \nby a backslash would cause the least disruption to existing .gitignore \nfiles.\n\n3. Like (2), but use a separate file instead of .gitignore (and the \nother git-ignore files).\n\nAny thoughts?\n\n-- \nhttps://david.mandelberg.org/\n"},{"id":"364006","messageId":"20181124145723.ow2h7x374xwwts6m@tigra","threadId":"49887","inReplyTo":"7ac49733-2e62-7d29-36aa-99df4124b54c@mandelberg.org","subject":"Re: git overwriting local ignored files?","fromName":"Konstantin Khomoutov","fromEmail":"kostix@bswap.ru","sentAt":"2018-11-24T14:57:24Z","receivedAt":"2018-11-24T14:57:41Z","isPatch":false,"sender":{"key":"kostix@bswap.ru","avatar":null},"body":"On Sat, Nov 24, 2018 at 09:37:06AM -0500, David Mandelberg wrote:\n\n> > > It seems that git is overwriting my local files on merge if they're in\n> > > .gitignore.\n[...]\n> > The .gitignore file is to list \"ignored and expendable\" class of\n> > files; there is no \"ignored but precious class\" in Git.\n> Ok. Would a patch be welcome? I have three ideas for how to implement it,\n> and I'm not sure which is better.\n[...]\n\nYou might want to first investigate this recent thread [1] which AFAIK\nwas dedicated to exactly this problem.\n\n1. https://public-inbox.org/git/4C6A1C5B.4030304@workspacewhiz.com/\n\n"},{"id":"364008","messageId":"20181124154132.co3lo27wy25i4v47@tigra","threadId":"49887","inReplyTo":"20181124145723.ow2h7x374xwwts6m@tigra","subject":"Re: git overwriting local ignored files?","fromName":"Konstantin Khomoutov","fromEmail":"kostix@bswap.ru","sentAt":"2018-11-24T15:41:32Z","receivedAt":"2018-11-24T15:41:45Z","isPatch":false,"sender":{"key":"kostix@bswap.ru","avatar":null},"body":"On Sat, Nov 24, 2018 at 05:57:24PM +0300, Konstantin Khomoutov wrote:\n> On Sat, Nov 24, 2018 at 09:37:06AM -0500, David Mandelberg wrote:\n> \n> > > > It seems that git is overwriting my local files on merge if they're in\n> > > > .gitignore.\n> [...]\n> > > The .gitignore file is to list \"ignored and expendable\" class of\n> > > files; there is no \"ignored but precious class\" in Git.\n> > Ok. Would a patch be welcome? I have three ideas for how to implement it,\n> > and I'm not sure which is better.\n> [...]\n> \n> You might want to first investigate this recent thread [1] which AFAIK\n> was dedicated to exactly this problem.\n\nWell, actually the thread is old, but its continuation [2] is recent.\nThe crux is that it discusses certain approaches to solve the apparent\nproblem and patches to do that.\n\n1. https://public-inbox.org/git/4C6A1C5B.4030304@workspacewhiz.com/\n2. https://public-inbox.org/git/871s8qdzph.fsf@evledraar.gmail.com/\n\n"},{"id":"364020","messageId":"89204364-f624-62ec-fbaa-84b5b7ae4099@mandelberg.org","threadId":"49887","inReplyTo":"20181124154132.co3lo27wy25i4v47@tigra","subject":"Re: git overwriting local ignored files?","fromName":"David Mandelberg","fromEmail":"david@mandelberg.org","sentAt":"2018-11-25T02:06:35Z","receivedAt":"2018-11-25T02:06:44Z","isPatch":false,"sender":{"key":"david@mandelberg.org","avatar":"https://avatars.githubusercontent.com/u/15314936?v=4"},"body":"On 11/24/18 10:41 AM, Konstantin Khomoutov wrote:\n> On Sat, Nov 24, 2018 at 05:57:24PM +0300, Konstantin Khomoutov wrote:\n>> On Sat, Nov 24, 2018 at 09:37:06AM -0500, David Mandelberg wrote:\n>>\n>>>>> It seems that git is overwriting my local files on merge if they're in\n>>>>> .gitignore.\n>> [...]\n>>>> The .gitignore file is to list \"ignored and expendable\" class of\n>>>> files; there is no \"ignored but precious class\" in Git.\n>>> Ok. Would a patch be welcome? I have three ideas for how to implement it,\n>>> and I'm not sure which is better.\n>> [...]\n>>\n>> You might want to first investigate this recent thread [1] which AFAIK\n>> was dedicated to exactly this problem.\n> \n> Well, actually the thread is old, but its continuation [2] is recent.\n> The crux is that it discusses certain approaches to solve the apparent\n> problem and patches to do that.\n> \n> 1. https://public-inbox.org/git/4C6A1C5B.4030304@workspacewhiz.com/\n> 2. https://public-inbox.org/git/871s8qdzph.fsf@evledraar.gmail.com/\n\nThanks for the pointers, and sorry to start a new thread. It looks like \nmost of the work to do is in finding consensus on the right way forward, \nrather than in writing a patch. While I really would like there be a way \nto prevent git from overwriting ignored files, I don't have any strong \nopinions on what that way should look like. So I think I'll just wait \nand hope somebody else does the work.\n\n-- \nhttps://david.mandelberg.org/\n"}]}