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

git clean -Xdf affects parent and sibling directories

From
JBJan Berges <jan.berges@uni-bremen.de>
Date
Feb 7, 2025, 20:14 UTC
Message-ID
<7d2cf91f-c4ac-41de-966d-3681ac549ef0@uni-bremen.de>
Dear Git Developers,
This is probably not a bug, but a potentially dangerous behavior.

What did you do before the bug happened? (Steps to reproduce your issue) 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.

Anything else you want to add: The behavior can be reproduced using the following lines.

mkdir git_clean_test/ cd git_clean_test/

git init -q

mkdir -p dir1/sub1/ mkdir -p dir1/sub2/ mkdir -p dir2/sub1/ mkdir -p dir2/sub2/

touch dir1/sub1/file touch dir1/sub2/file touch dir2/sub1/file touch dir2/sub2/file

echo -e "file\ndir1" > .gitignore
for dir in dir1/sub1/ dir2/sub1/
do
     cd $dir
     pwd
     git clean -Xdn
     cd ~-
done
Output of the above lines:

/home/jan/git_clean_test/dir1/sub1 Would refuse to remove current working directory Would remove ../sub1/file Would remove ../sub2 /home/jan/git_clean_test/dir2/sub1 Would refuse to remove current working directory Would remove ./file

Thanks and kind regards,
Jan
[System Info]
git version:
git version 2.48.1.575.g74a3c43834
cpu: x86_64
built from commit: 74a3c43834882219aa12aa1815d441a1762ba558
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
libcurl: 7.88.1
OpenSSL: OpenSSL 3.0.15 3 Sep 2024
uname: Linux 6.1.0-30-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.124-1 
(2025-01-12) x86_64
compiler info: gnuc: 12.2
libc info: glibc: 2.36
$SHELL (typically, interactive shell): /bin/bash
Next: Junio C Hamano
Message 1 of 3 in “git clean -Xdf affects parent and sibling directories”
  1. Jan BergesFeb 7, 2025
  2. Junio C HamanoFeb 7, 2025
  3. Jan BergesFeb 8, 2025

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.