From: Junio C Hamano <gitster@pobox.com>
To: Jan Berges <jan.berges@uni-bremen.de>
Cc: git@vger.kernel.org
Subject: Re: git clean -Xdf affects parent and sibling directories
Date: Fri, 07 Feb 2025 13:24:58 -0800 [thread overview]
Message-ID: <xmqq4j15fnx1.fsf@gitster.g> (raw)
In-Reply-To: <7d2cf91f-c4ac-41de-966d-3681ac549ef0@uni-bremen.de> (Jan Berges's message of "Fri, 7 Feb 2025 21:14:35 +0100")
Jan Berges <jan.berges@uni-bremen.de> writes:
> Run git clean -Xdf in a subdirectory of a directory ignored by Git.
>
> What did you expect to happen? (Expected behavior)
> All contents of this subdirectory are removed. From the man page:
> "Cleans the working tree [...], starting from the current directory"
>
> What happened instead? (Actual behavior)
> Ignored contents of parent and sibling directories are also removed.
Interesting observation.
Behind Git as a whole, there is a philosophy to track the entire
working tree as a single unit, so touching a file at the top-level
or in one subdirectory, going into a different subdirectory and
running "git status" and "git diff" would show changes, in line with
the spirit of tracking the whole tree as a single unit, made to that
file outside your current directory. Of course, if you add changes
to a file at the top-level or a subdirectory, chdir to a different
subdirectory, touch some other files there, and say "git commit -a",
these changes outside your current directory would also be recorded.
The behaviour comes from the same principle.
I think "git grep" is a notable oddball. Its UI is build around the
guess that end users would expect a similarity with vanilla "grep"
run with the "-r" option, so it only looks at the current directory
or below.
In hindsight, some may argue that "git clean" should also be an
exception, but I doubt that would have been a good UI even back
then, forcing end-users to remember which ones are always full-tree
operation and which ones are current-directory-and-below.
To limit the extent of potential damage, I'd always do a dry run
with "git clean -n" first, giving other arguments I intend to give
for the real run, and then swap "-n" with "-f". The command should
take the usual pathspec, so "git clean ." should work as expected.
HTH.
next prev parent reply other threads:[~2025-02-07 21:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-07 20:14 git clean -Xdf affects parent and sibling directories Jan Berges
2025-02-07 21:24 ` Junio C Hamano [this message]
2025-02-08 9:43 ` Jan Berges
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq4j15fnx1.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=jan.berges@uni-bremen.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.