From: "Mora de Sambricio, Javier Export License Required - US RTX-Ireland" <javier.moradesambricio@rtx.com>
To: "git@vger.kernel.org" <git@vger.kernel.org>
Cc: "cousteaulecommandant@gmail.com" <cousteaulecommandant@gmail.com>
Subject: BUG: Removing a submodule with --cached doesn't stage changes to the .gitmodules file
Date: Mon, 12 Oct 2020 13:45:40 +0000 [thread overview]
Message-ID: <ea91c2ea29064079914f6a522db5115a@UUSALE0Z.utcmail.com> (raw)
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
reply other threads:[~2020-10-12 14:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ea91c2ea29064079914f6a522db5115a@UUSALE0Z.utcmail.com \
--to=javier.moradesambricio@rtx.com \
--cc=cousteaulecommandant@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).