git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: gitignore excludes not working?

From
Jiang Xin <worldhello.net@gmail.com>
Date
Dec 7, 2013, 01:07 UTC
Message-ID
<CANYiYbG=qdoLmD9FkOPikjVeN9T69+U6KBGYyVc5NAvuiZ1rLA@mail.gmail.com>
In-Reply-To
<CACPiFCJ0Jj1M8KCrwus=DeRSBE2O3HKhvEo-UJhHoZDhHTzsSA@mail.gmail.com>
2013/12/7 Martin Langhoff <martin.langhoff@gmail.com>:
Show 31 quoted lines
> Tested with git 1.7.12.4 (Apple Git-37) and git 1.8.3.1 on F20.
>
> $ mkdir foo
> $ cd foo
> $ git init
> Initialized empty Git repository in /tmp/foo/.git/
> $ mkdir -p modules/boring
> $ mkdir -p modules/interesting
> $ touch modules/boring/lib.c
> $ touch modules/interesting/other.c
> $ touch modules/interesting/lib.c
> $ git add modules/interesting/lib.c
> $ git status
> # On branch master
> #
> # Initial commit
> #
> # Changes to be committed:
> #   (use "git rm --cached <file>..." to unstage)
> #
> # new file:   modules/interesting/lib.c
> #
> # Untracked files:
> #   (use "git add <file>..." to include in what will be committed)
> #
> # modules/boring/
> # modules/interesting/other.c
>
> $ echo '/modules/' > .gitignore
> $ echo '!/modules/interesting/' >> .gitignore
>

I happened to write a software "Gistore" to backup arbitrary files and directories using Git, and it will save interesting things in .git/info/exclude. For your case, you could write .gitignore as:

    /modules/*
    !/modules/interesting
    !/modules/interesting/**
You can find my code in Gistore to generate proper .gitignore here:
    https://github.com/jiangxin/gistore/blob/master/lib/gistore/repo.rb#L228
Because I will ignore all files except what I want, the ignore file would be:
   *
    !/modules
    !/modules/interesting
    !/modules/interesting/**
-- 
Jiang Xin
Previous: Martin LanghoffNext: Duy Nguyen
Message 2 of 3 in “gitignore excludes not working?”
  1. Martin LanghoffDec 6, 2013
  2. Jiang XinDec 7, 2013
  3. Duy NguyenDec 7, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.