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

Re: [RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Aug 12, 2010, 20:26 UTC
Message-ID
<AANLkTikV-fye7qc5kQNC5dSCTHB6nYoVfCg_PeFuk0KT@mail.gmail.com>
In-Reply-To
<AANLkTimODL6j11D6QuUX4b47GwFOVOXdqkhqrRfRaxmq@mail.gmail.com>
On Thu, Aug 12, 2010 at 15:54, Greg Brockman <gdb@mit.edu> wrote:
> Secondly, I don't think this makes '-f' useless.  '-f' would still be
> used to initially add an untracked file to the index.  So this would
> maintain an invariant that no ignored files are tracked unless the
> user has specified a '-f' for it in the past.

I initially misread what this series was about, and I was about to withdraw my support for it. But this seems completely reasonable, and actually I think Git's current behavior here is clearly a bug.

To elabore with examples this behavior here is fine, and I think everyone agrees with that:

    aoeu tmp (160M) $ git init meh
    Initialized empty Git repository in /tmp/meh/.git/
    aoeu tmp (160M) $ cd !$
    cd meh
    aoeu meh (master) $ echo '*' > .gitignore
    aoeu meh (master) $ mkdir ignore-dir
    aoeu meh (master) $ echo ignore > ignore-dir/file
    aoeu meh (master) $ echo ignore > file
    aoeu meh (master) $ git add file ignore-dir
    The following paths are ignored by one of your .gitignore files:
    file
    ignore-dir
    Use -f if you really want to add them.
    fatal: no files added

Here I have * in .gitignore but I'm adding files with an explicit path. Making this not ask for -f would be pretty bad, e.g. for the glob reasons Junio cited.

So I have to -f it:
    aoeu meh (master) $ git add -f file ignore-dir
    aoeu meh (master) $ git commit -m"commiting ignored stuff"
    [master (root-commit) 6cae514] commiting ignored stuff
     2 files changed, 2 insertions(+), 0 deletions(-)
     create mode 100644 file
     create mode 100644 ignore-dir/file
However this part I think is a bug:
    aoeu meh (master) $ echo whee >> ignore-dir/file
    aoeu meh (master) $ echo whee >> file
    aoeu meh (master) $ git status --short
     M file
     M ignore-dir/file
    aoeu meh (master) $ git add file
    aoeu meh (master) $ git add ignore-dir/file
    The following paths are ignored by one of your .gitignore files:
    ignore-dir
    Use -f if you really want to add them.
    fatal: no files added
    $ git status --short
    M  file
     M ignore-dir/file

Here "file" is already tracked by Git and it doesn't complain when I "git add" a update to it, but it complains about "ignore-dir/file" just because it's in a subdirectory.

I hadn't noticed this before because I usually use "git add -u", which doesn't complain about the ignore and happily updates the file in the index:

    aoeu meh (master) $ git add -u
    aoeu meh (master) $ git status --short
    M  file
    M  ignore-dir/file

I think "git add ignore-dir/file" above should act exactly like "git add file", and not force me to add a "-f" to "git add".

Previous: Jonathan NiederNext: Greg Brockman
Message 15 of 28 in “git-add: Don't exclude explicitly-specified tracked files”
  1. git-add: Don't exclude explicitly-specified tracked filesGreg Brockman, Aug 11, 2010
  2. Ævar Arnfjörð BjarmasonAug 11, 2010
  3. Jens LehmannAug 11, 2010
  4. Greg BrockmanAug 12, 2010
  5. Junio C HamanoAug 11, 2010
  6. Greg BrockmanAug 11, 2010
  7. Junio C HamanoAug 12, 2010
  8. Greg BrockmanAug 12, 2010
  9. Matthieu MoyAug 12, 2010
  10. Greg BrockmanAug 12, 2010
  11. Matthieu MoyAug 12, 2010
  12. Junio C HamanoAug 12, 2010
  13. Greg BrockmanAug 12, 2010
  14. Jonathan NiederAug 12, 2010
  15. Ævar Arnfjörð BjarmasonAug 12, 2010
  16. Greg BrockmanAug 18, 2010
  17. Add test case for dealing with a tracked file in an ignored directoryGreg Brockman, Aug 18, 2010
  18. Greg BrockmanAug 18, 2010
  19. Matthieu MoyAug 18, 2010
  20. Greg BrockmanAug 19, 2010
  21. Matthieu MoyAug 19, 2010
  22. Ævar Arnfjörð BjarmasonAug 18, 2010
  23. Matthieu MoyAug 18, 2010
  24. Ævar Arnfjörð BjarmasonAug 18, 2010
  25. Jonathan NiederAug 19, 2010
  26. Ævar Arnfjörð BjarmasonAug 19, 2010
  27. Jonathan NiederAug 25, 2010
  28. Ævar Arnfjörð BjarmasonAug 29, 2010

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.