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

BUG: Removing a submodule with --cached doesn't stage changes to the .gitmodules file

From
MRMora de Sambricio, Javier Export License Required - US RTX-Ireland <javier.moradesambricio@rtx.com>
Date
Oct 12, 2020, 13:45 UTC
Message-ID
<ea91c2ea29064079914f6a522db5115a@UUSALE0Z.utcmail.com>
Removing a submodule with --cached doesn't stage changes to the .gitmodules file

Command: `git rm [--cached] some_submodule`

Behavior without `--cached`:
- `some_submodule/` is deleted.
- The entry for `some_submodule` is deleted from `.gitmodules`.
- Both changes are staged.
Expected behavior with `--cached`:
- Neither `some_submodule` nor `.gitmodules` are actually modified in the work tree.
- `some_submodule` is staged for deletion.
- `.gitmodules` is staged for modification (removal of the entry for `some_submodule`).
Actual behavior with `--cached`:
- Neither `some_submodule` nor `.gitmodules` are actually modified in the work tree.
- `some_submodule` is staged for deletion.
- **`.gitmodules` is not staged for modification.**

Git version: Seen on git 2.25 (Linux) and 2.16 (Windows)

Workaround:
- I had to `mv` the directory outside of the project, `git rm -f` it (without `--cached`), and then `mv` it back into the project in order to have `.gitmodules` changed without actually deleting the `some_submodule/` subdirectory.
- Alternatively, manually edit `.gitmodules` and remove the submodule (this isn't a viable option for automated scripts, and can be a bit inconvenient when the `.gitmodules` file is too big).
Example code:

``` mkdir some_submodule cd some_submodule git init echo hello > hello.txt git add hello.txt git commit -m 'First commit of submodule' cd .. mkdir top_repo cd top_repo git init echo world > world.txt git add world.txt git commit -m 'First commit of top repo' git submodule add ../some_submodule git status # both some_submodule and .gitmodules staged git commit -m 'Added submodule' git rm --cached some_submodule git status # only some_submodule staged ```

Best regards,
        Javier Mora
Message 1 of 1 in “BUG: Removing a submodule with --cached doesn't stage changes to the .gitmodules file”
  1. Mora de Sambricio, Javier Export License Required - US RTX-IrelandOct 12, 2020

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.