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

Re: what should "git clean -n -f [-d] [-x] <pattern>" do?

From
Kristoffer Haugsbakk <code@khaugsbakk.name>
Date
Jan 29, 2024, 19:40 UTC
Message-ID
<7f97e5e4-c394-4403-94f1-6163fbd02e88@app.fastmail.com>
In-Reply-To
<87il3enc1i.fsf@osv.gnss.ru>
On Sat, Jan 27, 2024, at 14:25, Sergey Organov wrote:
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Sergey Organov <sorganov@gmail.com> writes:
I agree with Sergey.

Let’s suppose I’ve never used git-clean(1) (and I almost never use it). I read the man page to find out what it’s about. Oh, it removes files that I haven’t tracked. That sounds dangerous. But I see under `-n, --dry-run` that I can simulate what it would do:

   “ Don’t actually remove anything, just show what would be done.

Great, this is what I want. So this seems to mean to run `git clean` and just tell me what would happen. But now I’ve already read that it requires `--force` in order to do anything. Which means that I don’t want to just run:

``` git clean --dry-run ```

Since I presume that would give me the “no `--force` provided” error. Which means that I want to tack on `--force`:

``` git clean --dry-run --force ```

Now I figure that this will run `git clean --force` but switch real deletion with printing the filenames.[1]

Junio wrote:
> What I find broken is that giving one 'f' and one 'n' in different
> order, i.e. "-f -n" and "-n -f", does not do what I expect.  If you
> are choosing between do-it (f) and do-not-do-it (n), you ought to be
> able to rely on the usual last-one-wins rule.  That I find broken.

Now suppose I have noticed that some git(1) commands have these `--[no-]do-it` options. I know that I can leverage this to override a previous option. And that is useful when I for example have an alias with `--do-it` but for this invocation I want `--no-do-it`. I read about `--force` here but see that there is no `--no-force`. I then assume that the only things that have to do with `--force` or not is that option and the `requireForce` configuration variable.

I’ve also seen `--force` in other git(1) commands. And they usually are about some specific scenario rather than the whole command itself, since e.g. committing one too many times doesn’t really hurt. But I understand how `--force` applies to all the useful work that git-clean(1) does because all the useful work is also destructive work. So this is what I expect from these options in general:

1. `--force`: require for the subset of actions that are potentially
   dangerous or may be unwanted in some way
2. `--dry-run`: simulate the action (specifically print everything that
   would happen but don’t do anything to `.git`, to untracked files, or
   anything else)

And I expect these two to be orthogonal. Because I might want—if the option is there—to simulate some `--force` (e.g. `git push --force`) with a `--dry-run`. As in: what would be printed? I wouldn’t expect `--force` to override `--dry-run`.

† 1: I’m never this careful in real life. But this is about deleting
   files without any (from Git) recovery so I guess some prudence is
   required in this case.
-- 
Kristoffer Haugsbakk
Previous: Sergey OrganovNext: Sergey Organov
Message 16 of 38 in “what should "git clean -n -f [-d] [-x] <pattern>" do?”
  1. Junio C HamanoJan 9, 2024
  2. Sergey OrganovJan 9, 2024
  3. Elijah NewrenJan 19, 2024
  4. Sergey OrganovJan 23, 2024
  5. Junio C HamanoJan 23, 2024
  6. Sergey OrganovJan 24, 2024
  7. Junio C HamanoJan 24, 2024
  8. Sergey OrganovJan 25, 2024
  9. Junio C HamanoJan 25, 2024
  10. Sergey OrganovJan 25, 2024
  11. Sergey OrganovJan 25, 2024
  12. Junio C HamanoJan 26, 2024
  13. Sergey OrganovJan 26, 2024
  14. Junio C HamanoJan 27, 2024
  15. Sergey OrganovJan 27, 2024
  16. Kristoffer HaugsbakkJan 29, 2024
  17. Sergey OrganovJan 31, 2024
  18. Sergey OrganovJan 29, 2024
  19. Jeff KingJan 29, 2024
  20. Sergey OrganovJan 29, 2024
  21. Jeff KingJan 30, 2024
  22. Junio C HamanoJan 30, 2024
  23. clean: improve -n and -f implementation and documentationSergey Organov, Feb 29, 2024
  24. Jean-Noël AvilaMar 1, 2024
  25. Sergey OrganovMar 1, 2024
  26. Kristoffer HaugsbakkMar 1, 2024
  27. Junio C HamanoMar 1, 2024
  28. Jean-Noël AVILAMar 2, 2024
  29. Sergey OrganovMar 2, 2024
  30. Junio C HamanoMar 2, 2024
  31. Sergey OrganovMar 2, 2024
  32. Sergey OrganovMar 3, 2024
  33. Junio C HamanoMar 1, 2024
  34. Junio C HamanoMar 1, 2024
  35. Sergey OrganovMar 1, 2024
  36. Junio C HamanoMar 2, 2024
  37. Sergey OrganovMar 2, 2024
  38. clean: improve -n and -f implementation and documentationSergey Organov, Mar 3, 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.