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

Re: [RFC] Define "precious" attribute and support it in `git clean`

From
Jeff King <peff@peff.net>
Date
Oct 11, 2023, 22:40 UTC
Message-ID
<20231011224002.GD518221@coredump.intra.peff.net>
In-Reply-To
<AS8PR02MB73027943EE0A30DD8DAAD4639CCCA@AS8PR02MB7302.eurprd02.prod.outlook.com>
On Wed, Oct 11, 2023 at 10:06:25AM +0000, Richard Kerry wrote:
Show 15 quoted lines
> The version of CVS that I used to use, CVSNT, was a lot more careful
> about the user's files than Git is inclined to be.
> If CVSNT, while doing an Update, came across a non-tracked file that
> was in the way of something that it wanted to write, then the Update
> would be aborted showing a list of any files that were "in the way".
> The user could then rename/delete them or redo the Update with a
> "force" parameter to indicate that such items could be overwritten.
> Git has tended to take an approach of "if it's important it'll be
> tracked by Git - anything else can be trashed with impunity.".  Over
> the years people have been caught out by this and lost work.  It may
> well be that in a Linux development world anything other than tracked
> source files can be summarily deleted, but in a wider world, like
> Windows, or environments that are not software development, or that
> need special files lying around, this is not always an entirely
> reasonable approach.

I'm not sure if you are just skipping the details of ".gitignore" here, but to be clear, blowing away untracked files is _not_ Git's default behavior.

For example:
  [sample repo with established history]
  $ git init
  $ echo content >base
  $ git add base
  $ git commit -m base
  [one branch touches some-file]
  $ git checkout -b side-branch
  $ echo whatever >some-file
  $ git add some-file
  $ git commit -m 'add some-file'
  [but back on master/main, it is untracked]
  $ git checkout main
  $ echo precious >some-file
  [an operation that tries to overwrite the untracked file will fail]
  $ git checkout side-branch
  $ git checkout side-branch
  error: The following untracked working tree files would be overwritten by checkout:
	some-file
  Please move or remove them before you switch branches.
  Aborting
  [providing --force will obliterate it]
  $ git checkout --force side-branch
  Switched to branch 'side-branch'

The issue that people sometimes find with Git is when the user has explicitly listed a file in ".gitignore", Git takes that to mean it should never be tracked _and_ it is not precious. But people sometimes want a way to say "this should never be tracked, but keep treating it as precious in the usual way".

From the description above it might sound like Git's current behavior is conflating two orthogonal things, but if you switched the default behavior of .gitignore'd files to treat them as precious, you will find lots of cases that are annoying. E.g., if a file is generated by some parts of history and tracked in others, you'd have to use --force to move between them to overwrite the generated version.

-Peff
Previous: Richard KerryNext: Junio C Hamano
Message 10 of 28 in “[RFC] Define "precious" attribute and support it in `git clean`”
  1. Sebastian ThielOct 10, 2023
  2. Kristoffer HaugsbakkOct 10, 2023
  3. Josh TriplettOct 10, 2023
  4. Junio C HamanoOct 10, 2023
  5. Josh TriplettOct 12, 2023
  6. Kristoffer HaugsbakkOct 10, 2023
  7. Josh TriplettOct 12, 2023
  8. Junio C HamanoOct 10, 2023
  9. Richard KerryOct 11, 2023
  10. Jeff KingOct 11, 2023
  11. Junio C HamanoOct 11, 2023
  12. Sebastian ThielOct 12, 2023
  13. Junio C HamanoOct 12, 2023
  14. Sebastian ThielOct 13, 2023
  15. Junio C HamanoOct 13, 2023
  16. Sebastian ThielOct 14, 2023
  17. Phillip WoodOct 13, 2023
  18. Junio C HamanoOct 14, 2023
  19. Oswald BuddenhagenOct 13, 2023
  20. Josh TriplettOct 14, 2023
  21. Junio C HamanoOct 14, 2023
  22. Elijah NewrenOct 15, 2023
  23. Sebastian ThielOct 15, 2023
  24. Junio C HamanoOct 15, 2023
  25. Sebastian ThielOct 16, 2023
  26. Sebastian ThielOct 23, 2023
  27. Elijah NewrenOct 29, 2023
  28. Kristoffer HaugsbakkOct 11, 2023

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.