Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does git clean --dry-run shows more untracked files than git status does?

Tags:

git

github

Ok so I forked a project, ran git pull upstream master and git status said working directory clean. I then ran some tests from the project

now git status shows

# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   activemodel/log/

now $ git clean -d -f -n shows

# Would remove actionpack/test/temp/
# Would remove activemodel/log/

These are just directories for log files but I'm curious why actionpack/test/temp/ shows up in the git clean dry run but didn't show up in git status

This could cause problems if all untracked files don't show up in git status and then git clean would delete files you didn't realize it would delete.

Anybody know why this happens?

like image 690
fontno Avatar asked Oct 24 '25 15:10

fontno


1 Answers

Are they empty directories?

Git does not track empty directories (actually Git does not track directories at all, as you can read in the Git FAQ), so they will not appear in git status, but they would indeed be cleaned by git clean -f -d.

That's why a dry run of such git-clean command is showing directories that do not appear otherwise with a regular git status.

As a side note, this is also why some people add a placeholder file, sometimes called .gitinclude by convention, inside empty directories in order to make Git track them.

like image 151
Gabriele Petronella Avatar answered Oct 27 '25 03:10

Gabriele Petronella