{"thread":{"id":"35490","subject":"gitignore excludes not working?","startedAt":"2013-12-06T17:26:59Z","lastAt":"2013-12-07T03:20:46Z","messageCount":3,"participants":["Martin Langhoff","Jiang Xin","Duy Nguyen"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"231661","messageId":"CACPiFCJ0Jj1M8KCrwus=DeRSBE2O3HKhvEo-UJhHoZDhHTzsSA@mail.gmail.com","threadId":"35490","inReplyTo":null,"subject":"gitignore excludes not working?","fromName":"Martin Langhoff","fromEmail":"martin.langhoff@gmail.com","sentAt":"2013-12-06T17:26:59Z","receivedAt":"2013-12-06T17:26:59Z","isPatch":false,"sender":{"key":"martin.langhoff@gmail.com","avatar":"https://gravatar.com/avatar/1e3f311b6c4c15836501901ca58f8c0b0667246488084ba524d8bc9867e22fd9?d=mp&s=160"},"body":"Tested with git 1.7.12.4 (Apple Git-37) and git 1.8.3.1 on F20.\n\n$ mkdir foo\n$ cd foo\n$ git init\nInitialized empty Git repository in /tmp/foo/.git/\n$ mkdir -p modules/boring\n$ mkdir -p modules/interesting\n$ touch modules/boring/lib.c\n$ touch modules/interesting/other.c\n$ touch modules/interesting/lib.c\n$ git add modules/interesting/lib.c\n$ git status\n# On branch master\n#\n# Initial commit\n#\n# Changes to be committed:\n#   (use \"git rm --cached <file>...\" to unstage)\n#\n# new file:   modules/interesting/lib.c\n#\n# Untracked files:\n#   (use \"git add <file>...\" to include in what will be committed)\n#\n# modules/boring/\n# modules/interesting/other.c\n\n$ echo '/modules/' > .gitignore\n$ echo '!/modules/interesting/' >> .gitignore\n\nOn this git status, I would expect to see modules/interesting/other.c\nlisted as untracked, however:\n\n$ git status\n# On branch master\n#\n# Initial commit\n#\n# Changes to be committed:\n#   (use \"git rm --cached <file>...\" to unstage)\n#\n# new file:   modules/interesting/lib.c\n#\n# Untracked files:\n#   (use \"git add <file>...\" to include in what will be committed)\n#\n# .gitignore\n\n\nthoughts?\n\n\n\nm\n-- \n martin.langhoff@gmail.com\n -  ask interesting questions\n - don't get distracted with shiny stuff  - working code first\n ~ http://docs.moodle.org/en/User:Martin_Langhoff\n"},{"id":"231691","messageId":"CANYiYbG=qdoLmD9FkOPikjVeN9T69+U6KBGYyVc5NAvuiZ1rLA@mail.gmail.com","threadId":"35490","inReplyTo":"CACPiFCJ0Jj1M8KCrwus=DeRSBE2O3HKhvEo-UJhHoZDhHTzsSA@mail.gmail.com","subject":"Re: gitignore excludes not working?","fromName":"Jiang Xin","fromEmail":"worldhello.net@gmail.com","sentAt":"2013-12-07T01:07:46Z","receivedAt":"2013-12-07T01:07:46Z","isPatch":false,"sender":{"key":"worldhello.net@gmail.com","avatar":"https://avatars.githubusercontent.com/u/183860?v=4"},"body":"2013/12/7 Martin Langhoff <martin.langhoff@gmail.com>:\n> Tested with git 1.7.12.4 (Apple Git-37) and git 1.8.3.1 on F20.\n>\n> $ mkdir foo\n> $ cd foo\n> $ git init\n> Initialized empty Git repository in /tmp/foo/.git/\n> $ mkdir -p modules/boring\n> $ mkdir -p modules/interesting\n> $ touch modules/boring/lib.c\n> $ touch modules/interesting/other.c\n> $ touch modules/interesting/lib.c\n> $ git add modules/interesting/lib.c\n> $ git status\n> # On branch master\n> #\n> # Initial commit\n> #\n> # Changes to be committed:\n> #   (use \"git rm --cached <file>...\" to unstage)\n> #\n> # new file:   modules/interesting/lib.c\n> #\n> # Untracked files:\n> #   (use \"git add <file>...\" to include in what will be committed)\n> #\n> # modules/boring/\n> # modules/interesting/other.c\n>\n> $ echo '/modules/' > .gitignore\n> $ echo '!/modules/interesting/' >> .gitignore\n>\n\nI happened to write a software \"Gistore\" to backup arbitrary files and\ndirectories using Git, and it will save interesting things in .git/info/exclude.\nFor your case, you could write .gitignore as:\n\n    /modules/*\n    !/modules/interesting\n    !/modules/interesting/**\n\nYou can find my code in Gistore to generate proper .gitignore here:\n\n    https://github.com/jiangxin/gistore/blob/master/lib/gistore/repo.rb#L228\n\nBecause I will ignore all files except what I want, the ignore file would be:\n\n   *\n    !/modules\n    !/modules/interesting\n    !/modules/interesting/**\n\n\n-- \nJiang Xin\n"},{"id":"231693","messageId":"CACsJy8CyvSP9y7ui=2h7oFyeYCJK7WTdpqoSk00SM=LdpEokyQ@mail.gmail.com","threadId":"35490","inReplyTo":"CACPiFCJ0Jj1M8KCrwus=DeRSBE2O3HKhvEo-UJhHoZDhHTzsSA@mail.gmail.com","subject":"Re: gitignore excludes not working?","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2013-12-07T03:20:46Z","receivedAt":"2013-12-07T03:20:46Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sat, Dec 7, 2013 at 12:26 AM, Martin Langhoff\n<martin.langhoff@gmail.com> wrote:\n> # Untracked files:\n> #   (use \"git add <file>...\" to include in what will be committed)\n> #\n> # modules/boring/\n> # modules/interesting/other.c\n>\n> $ echo '/modules/' > .gitignore\n> $ echo '!/modules/interesting/' >> .gitignore\n\nOnce you ignore the directory \"modules\", it won't bother with anything\ninside. As a result, !/modules/interesting/ is ignored. Turning the\nfirst rule to /modules/* like Jiang Xin showed does the trick because\ngit is told to ignore entries inside 'modules', not 'modules' itself.\n\nI think the best we could do is turning /modules/ into /modules/*\ninternally. But it only works for simple cases like yours. If you\nwrite /mo*ules/, I don't think we can make git smart enough to\ncorrelate /mo*ules/ to !/modules/interesting/. So the second best\nthing is improve documents about this case, which is what\nkb/doc-exclude-directory-semantics does (currently on 'next').\n-- \nDuy\n"}]}