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

Re: [RFC PATCH] Introduce "precious" file concept

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Nov 12, 2018, 09:49 UTC
Message-ID
<87o9au39s7.fsf@evledraar.gmail.com>
In-Reply-To
<1205132135.1189562.1542013731020.JavaMail.zimbra@matthieu-moy.fr>
On Mon, Nov 12 2018, Matthieu Moy wrote:
Show 22 quoted lines
> "Per Lundberg" <per.lundberg@hibox.tv> wrote:
>
>> On 11/11/18 5:41 PM, Duy Nguyen wrote:
>> > On Sun, Nov 11, 2018 at 1:33 PM Ævar Arnfjörð Bjarmason
>> > <avarab@gmail.com> wrote:
>>
>> >> That will lose no data, and in the very rare cases where a checkout of
>> >> tracked files would overwrite an ignored pattern, we can just error out
>> >> (as we do with the "Ok to overwrite" branch removed) and tell the user
>> >> to delete the files to proceed.
>> > There's also the other side of the coin. If this refuse to overwrite
>> > triggers too often, it can become an annoyance.
>
> I may have missed some cases, but to me the cases when checkout may try
> to overwrite an ignored file are essentially:
>
> * Someone "git add"ed a file meant to be ignored by mistake (e.g.
>   "git add -f *.o").
>
> * A file that was meant to be kept private (e.g. config.mak.dev) ends
>   up being tracked. This may happen when we find a way to make per-developer
>   settings the same for everyone.

Yes, the cases under discussion here are all cases where a tracked file clobbers a file matching a pattern in in .gitignore.

What I'd add to your list is:
* Some projects (I've seen this in the wild) add e.g. *.mp3 or whatever
  else usually doesn't belong in the repo as a "soft ignore". This is
  something we've never recommended, but have implicitly supported since
  the only caveats are a) you need a one-off "git add -f" and then
  they're tracked b) them being missing from "status" before being
  tracked c) the issue under discussion here.
* Cases where e.g. filename changes to a directory or globs because of
  that make this more complex.
Show 27 quoted lines
> I both cases I'd want at least to be notified that something is going on,
> and in the second I'd probably want to keep my local file around.
>> If we feel thrashable is stretching it too far (which I don't think it
>> is), we could add a "core.ignore_files_are_trashable" setting that
>> brings back the old semantics, for those who have a strong feeling about it.
>
> May I remind an idea I sugested in an old thread: add an intermediate level
> where ignored files to be overwritten are renamed (eg. foo -> foo~ like Emacs'
> backup files):
>
> https://public-inbox.org/git/vpqd3t9656k.fsf@bauges.imag.fr/
>
> One advantage of the "rename" behavior is that it's safer that the current,
> but still not very disturbing for people who like the current behavior. This
> makes it a good candidate for a default behavior.
>
> This could come in complement with this thread's "precious" concept:
>
> * If you know what you're doing and know that such or such file is precious,
>   mark it as such and Git will never overwrite it.
>
> * If you don't know about precious files, just keep the default setting and
>   the worse that can happen is to get your file overwritten with a bakup
>   of the old version kept around.
>
> This would probably play better with a notion of "precious" files than with
> a notion of "trashable" files.

I used to think this foo -> foo~ approach made the most sense (and said as much in https://public-inbox.org/git/871s8qdzph.fsf@evledraar.gmail.com/) but I think it's probably best not to do it and just error out, because:

 * We'd still need to handle the cases where "tests" the file collides
   with "tests" the directory. Then where do we move the colliding file?
   ~/.git/lost+found/* ? We could handle the subdir case with another
   special-case though...
 * I think such silent action will just leave users more confused, and
   in many cases (e.g. a merge) whatever message we print out will be
   missed in a deluge of other messaging, and they'll probably miss it.
   I'd like to avoid a case where a bunch of *~ files get committed
   because the user's workflow is (and some beginner git users do this):
       git pull && git add . && git commit && git push
   As the "pull" would now invoke a merge that would do this rename.
 * If I have the "foo" file open in my editor (a plausible way to run
   into this) I switch to another terminal, do the merge, miss the
   message, then re-save "foo". Now I have both "foo" and "foo~"
   on-disk. Another case where we should just refuse until the user
   resolves the situation to avoid the confusion.
Previous: Matthieu MoyNext: Junio C Hamano
Message 10 of 40 in “Introduce "precious" file concept”
  1. Introduce "precious" file conceptNguyễn Thái Ngọc Duy, Nov 11, 2018
  2. Bert WesargNov 11, 2018
  3. Ævar Arnfjörð BjarmasonNov 11, 2018
  4. Ævar Arnfjörð BjarmasonNov 11, 2018
  5. Duy NguyenNov 12, 2018
  6. Duy NguyenNov 11, 2018
  7. Ævar Arnfjörð BjarmasonNov 11, 2018
  8. Per LundbergNov 12, 2018
  9. Matthieu MoyNov 12, 2018
  10. Ævar Arnfjörð BjarmasonNov 12, 2018
  11. Junio C HamanoNov 12, 2018
  12. Ævar Arnfjörð BjarmasonNov 12, 2018
  13. Junio C HamanoNov 12, 2018
  14. Duy NguyenNov 12, 2018
  15. brian m. carlsonNov 12, 2018
  16. Per LundbergNov 26, 2018
  17. Ævar Arnfjörð BjarmasonNov 26, 2018
  18. Junio C HamanoNov 26, 2018
  19. Ævar Arnfjörð BjarmasonNov 27, 2018
  20. Junio C HamanoNov 28, 2018
  21. Ævar Arnfjörð BjarmasonNov 28, 2018
  22. Junio C HamanoNov 29, 2018
  23. Duy NguyenDec 1, 2018
  24. Duy NguyenNov 26, 2018
  25. Ævar Arnfjörð BjarmasonNov 26, 2018
  26. Duy NguyenNov 26, 2018
  27. Ævar Arnfjörð BjarmasonNov 26, 2018
  28. Duy NguyenNov 26, 2018
  29. Per LundbergNov 27, 2018
  30. Jacob KellerNov 27, 2018
  31. Per LundbergNov 27, 2018
  32. brian m. carlsonNov 28, 2018
  33. Per LundbergNov 28, 2018
  34. Duy NguyenNov 27, 2018
  35. Duy NguyenDec 6, 2018
  36. Eckhard MaaßNov 26, 2018
  37. Junio C HamanoNov 11, 2018
  38. 0/2 Precios files round twoNguyễn Thái Ngọc Duy, Nov 26, 2018
  39. 1/2 Introduce "precious" file conceptNguyễn Thái Ngọc Duy, Nov 26, 2018
  40. 2/2 unpack-trees: support core.allIgnoredFilesArePreciousWhenMergingNguyễn Thái Ngọc Duy, Nov 26, 2018

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.