{"thread":{"id":"54399","subject":"BUG: Removing a submodule with --cached doesn't stage changes to the .gitmodules file","startedAt":"2020-10-12T14:24:29Z","lastAt":"2020-10-12T14:24:29Z","messageCount":1,"participants":["Mora de Sambricio, Javier Export License Required - US RTX-Ireland"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"407337","messageId":"ea91c2ea29064079914f6a522db5115a@UUSALE0Z.utcmail.com","threadId":"54399","inReplyTo":null,"subject":"BUG: Removing a submodule with --cached doesn't stage changes to the .gitmodules file","fromName":"Mora de Sambricio, Javier Export License Required - US RTX-Ireland","fromEmail":"javier.moradesambricio@rtx.com","sentAt":"2020-10-12T13:45:40Z","receivedAt":"2020-10-12T14:24:29Z","isPatch":false,"sender":{"key":"javier.moradesambricio@rtx.com","avatar":null},"body":"Removing a submodule with --cached doesn't stage changes to the .gitmodules file\n\nCommand:\n`git rm [--cached] some_submodule`\n\nBehavior without `--cached`:\n- `some_submodule/` is deleted.\n- The entry for `some_submodule` is deleted from `.gitmodules`.\n- Both changes are staged.\n\nExpected behavior with `--cached`:\n- Neither `some_submodule` nor `.gitmodules` are actually modified in the work tree.\n- `some_submodule` is staged for deletion.\n- `.gitmodules` is staged for modification (removal of the entry for `some_submodule`).\n\nActual behavior with `--cached`:\n- Neither `some_submodule` nor `.gitmodules` are actually modified in the work tree.\n- `some_submodule` is staged for deletion.\n- **`.gitmodules` is not staged for modification.**\n\nGit version:\nSeen on git 2.25 (Linux) and 2.16 (Windows)\n\nWorkaround:\n- 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.\n- 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).\n\n\n\nExample code:\n\n```\nmkdir some_submodule\ncd some_submodule\ngit init\necho hello > hello.txt\ngit add hello.txt\ngit commit -m 'First commit of submodule'\ncd ..\nmkdir top_repo\ncd top_repo\ngit init\necho world > world.txt\ngit add world.txt\ngit commit -m 'First commit of top repo'\ngit submodule add ../some_submodule\ngit status  # both some_submodule and .gitmodules staged\ngit commit -m 'Added submodule'\ngit rm --cached some_submodule\ngit status  # only some_submodule staged\n```\n\n\n\nBest regards,\n        Javier Mora\n"}]}