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

Re: Fwd: Unexpected behavior of ls-files command when using --others --exclude-from, and a .gitignore file which resides in a subdirectory

From
Raúl Núñez de Arenas Coronado <raulnac@gmail.com>
Date
Jan 23, 2024, 05:40 UTC
Message-ID
<CAGF1KhWaOrnV8d2f_vajOT0hFK2N_8m7-p_vnZhw92ZdhXfsag@mail.gmail.com>
In-Reply-To
<20240122213410.GA811766@coredump.intra.peff.net>
Hi Jeff, and thanks for your reply :)
El lun, 22 ene 2024 a las 22:34, Jeff King (<peff@peff.net>) escribió:
Show 26 quoted lines
> For example, I get:
>
>   [setup]
>   $ git init
>   $ mkdir subdir
>   $ echo '*' >subdir/.gitignore
>   $ git add -f subdir/.gitignore && git commit -m "add gitignore"
>   $ touch subdir/file file
>
>   [no exclusions]
>   $ git ls-files -o
>   file
>   subdir/file
>
>   [use .gitignore]
>   $ git ls-files --exclude-per-directory=.gitignore -o
>   file
>
>   [using standard excludes]
>   $ git ls-files --exclude-standard -o
>   file
>
> Do you get different results from that toy repo? If not, then what is
> different about your main repo? Do you perhaps have a stray "*" match
> somewhere in .git/info/exclude, etc? Or are you still providing
> --exclude-from in addition to --exclude-standard?

The difference lies in how I deal in my computer with ignored files. I have some files in all my repos which have to be ignored always, so I have that pattern in my core.excludes file. BUT those files have to be backed up on my system, just in case my local copy of the repo is lost for some reason, as they are files I need for development in my personal machine.

If I use --exclude-standard, no matter if those files are being ignored by core.excludes OR .git/info/exclude, they won't appear in that 'list other files' command output.

So, my previous idea was ignore ONLY those files ignored by the repository .gitignore file. That way, the other files that go in my core.excludes or .git/info/exclude will be listed and backed up. The problem here is that some of the repository gitignored files (files related to building, testing, etc.) have their own .gitignore file containing '*", but they are NOT present in the repo .gitignore. This is a common practice for Python virtual environments, for example.

Summing up: or I end up backing up those directories that have their own .gitignore file (not the end of the world) or I use a different solution to decide which files are ignored but "precious" (I love that concept, see Junio C Hamano message for that) OR I add those directories to the .gitignore present in the repo. This last idea I don't like very much, as they are particular to my system, not the repo, for example, *I* may decide to use ESLint and node_modules for some particular web page I'm writing, but the related configuration should not go into the repository and should not be ignored in .gitignore, but in .git/info/exclude. I won't backup node_modules, of course, it is going to be recreated, but I may want to back up packages.json and .eslintrc. And both of those files will go into .git/info/exclude, so if I use --exclude-standard, they won't be backed up.

Since as both Junio and you correctly pointed, this is in fact the expected, I'll try to find a different solution while the "precious" concept is finally implemented. I have a couple of ideas, like using a .giprecious file which my backup script can process easily, containing the untracked files to back-up.

Thanks for the toy repo, helped me test the differences with my setup!
-- 
Raúl Núñez de Arenas Coronado
.
Previous: Jeff KingNext: Jeff King
Message 12 of 14 in “Fwd: Unexpected behavior of ls-files command when using --others --exclude-from, and a .gitignore file which resides in a subdirectory”
  1. Raúl Núñez de Arenas CoronadoJan 22, 2024
  2. Junio C HamanoJan 22, 2024
  3. Raúl Núñez de Arenas CoronadoJan 22, 2024
  4. Junio C HamanoJan 22, 2024
  5. Raúl Núñez de Arenas CoronadoJan 23, 2024
  6. Jeff KingJan 22, 2024
  7. Junio C HamanoJan 22, 2024
  8. Jeff KingJan 22, 2024
  9. Elijah NewrenJan 24, 2024
  10. Junio C HamanoJan 24, 2024
  11. Jeff KingJan 24, 2024
  12. Raúl Núñez de Arenas CoronadoJan 23, 2024
  13. Jeff KingJan 24, 2024
  14. Raúl Núñez de Arenas CoronadoJan 24, 2024

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.