Git-clean is not safe when there is a submodule tracked in a local branch that is not tracked in the mainline branch. Running git-clean from the mainline branch when we have unpushed changes in a submodule tracked only in a local branch can lose local changes to that submodule permanentely. I have accidentally lost changes in this way when working with very large projects where a git-clean is more reliable than a makefile's "make clean". By changing the default behavior of git-clean to not delete the .git directories allows the history of the submodules to be recovered. # Example of issue: # # Clone mainline project git clone git://github.com/thoughtbot/paperclip.git cd paperclip/ # Add a submodule not tracked by mainline git checkout -b test_submodule_clean git submodule add git://github.com/technoweenie/attachment_fu.git attachement_fu git commit -m "add submodule" # Make a modification to the submodule. Note that we haven't pushed the change cd attachement_fu/ git checkout -b mod_readme_in_submodule vi README git add README git commit -m "Small change in submodule" # Go back to mainline's master branch and do a clean cd .. git checkout master git clean -f -d # Our change to the submodule, that was never pushed, is now gone forever # because all the history stored in the submodule's .git direct is deleted. # There is no recovering from this. # This breaks the "git must be safe" rule, as we've lost potentially a lot of # changes to any submodule projects that didn't get pushed yet. Solve # this issue by not deleting any .git directories we come across during a # git-clean, unless the "-m" option is passed to git-clean. This is my first email submittal using git, so apologies in advance for any formatting issues Jason Holden (2): Add option to not delete a .git directory in remove_dir_recursively() Don't clean any untracked submodule's .git dir by default in git-clean Documentation/git-clean.txt | 6 +++++- builtin-clean.c | 15 +++++++++++++-- builtin-clone.c | 4 ++-- dir.c | 17 +++++++++++++++-- dir.h | 2 +- refs.c | 2 +- transport.c | 4 ++-- 7 files changed, 39 insertions(+), 11 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html