0

I'm having trouble understanding what does git rm --cached do.

For example, I have a beagle_pft_test repo and a list of submodules inside "components folder". doing git rm --cached would delete it form the .git folder?:

enter image description here

Because when I type the following:

git rm --cached components/ChrgTmptrSen

And I get:

rm 'components/ChrgTmptrSen'

But I still see the component in the .git folder:

enter image description here

I'm not sure where did it remove it from? If I still see it in the .git folder, the .gitsubmodules file and the physical component in my local working directory

tadm123
  • 8,294
  • 7
  • 28
  • 44
  • Does this answer your question? [Remove a file from a Git repository without deleting it from the local filesystem](https://stackoverflow.com/questions/1143796/remove-a-file-from-a-git-repository-without-deleting-it-from-the-local-filesyste) – Gastón Schabas Apr 30 '23 at 20:52
  • If you `git rm file`, commit, then check out the previous commit, do you expect `file` to be there? – Guildenstern Apr 30 '23 at 21:37
  • Gaston, from the link it says that running `git rm --cached` deletes it from the index in the `.git` folder, but when I run it I still see it. I took a screenshot of it. – tadm123 Apr 30 '23 at 21:43
  • @tadm123: "the index" is a part inside git storage, git lingo for files on disk is "the worktree". The `--cached` in `git rm --cached` is precisely about telling git to stop tracking these files (remove them from the index), but *leave them on disk* (leve them in the worktree) -- you will still see them in the explorer. – LeGEC May 01 '23 at 04:20

1 Answers1

1

As I mentioned in "How do I remove a submodule?", you would need git submodule deinit -f -- a/submodule to unregister the given submodules, i.e. remove the whole submodule.$name section from .git/config folder. Plus a rm -rf .git/modules/a/submodule for cleanup.

The git rm --cached a/submodule is only needed if you still want the submodule files to still be visible on your disk, while the gitlink (special entry in the index) is removed from Git.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Is this special entry in the index on the hidden `.git` folder on the repository? If so that's strange because when I type `git rm --cached a/submodule` with the path that I want to erase, I still see it on that `.git` folder as if nothing was deleted – tadm123 May 01 '23 at 01:53
  • 2
    @tadm123 No, the special entry is just the sha1 of the submodule, and has nothing to do with a .git. – VonC May 01 '23 at 09:15