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

[PATCH 0/2] Don't delete untracked submodule's .git dirs by default

From
JHJason Holden <jason.k.holden@gmail.com>
Date
Jun 30, 2009, 02:10 UTC
Message-ID
<1246327845-22718-1-git-send-email-jason.k.holden@gmail.com>

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(-)
Next: Jason Holden
Message 1 of 10 in “Don't delete untracked submodule's .git dirs by default”
  1. 0/2 Don't delete untracked submodule's .git dirs by defaultJason Holden, Jun 30, 2009
  2. 1/2 Add option to not delete a .git directory in remove_dir_recursively()Jason Holden, Jun 30, 2009
  3. 2/2 Don't clean any untracked submodule's .git dir by default in git-cleanJason Holden, Jun 30, 2009
  4. Paolo BonziniJun 30, 2009
  5. Johannes SixtJun 30, 2009
  6. Junio C HamanoJun 30, 2009
  7. Junio C HamanoJun 30, 2009
  8. Jason HoldenJul 1, 2009
  9. Junio C HamanoJul 1, 2009
  10. Johannes SixtJun 30, 2009

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.