0

I have a symbolic link to a folder in one of the subfolders in my git repo called base. I have already tracked and uploaded this symbolic link (which is treated as a file in git2) to my repo, which is why even when I adjust my .gitignore to include this folder, it still tracks it. To fix this you normally run git rm --cached <file-name>1.

I've gone to the directory that base is in and have tried:

git rm --cached base

However, I get:

fatal: pathspec 'base' did not match any files

I've also tried this and get the same error:

git rm --cached ./base

It is a symbolic link so no trailing / necessary, however it does not work.

My question is, how do I remove a symbolic link from being tracked in git?

[1] How to make Git "forget" about a file that was tracked but is now in .gitignore? [2] How do I make Git ignore symlink?

Jessica
  • 1,083
  • 2
  • 12
  • 27
  • 1
    What operating system are you on? Does running `ls` in that directory show the name in a different case? – bk2204 Jul 09 '21 at 15:21
  • The error message you're seeing says that `base` *isn't* in Git's index right now, i.e., is not tracked. You would get this error if you try to `git rm --cached base` twice in a row, for instance: the first one removes it from Git's index, and the second complains because it's not there to remove. – torek Jul 09 '21 at 21:24

1 Answers1

0

I don't know why it isn't working, but it shouldn't actually matter because there's an easy work around:

  1. Save the file outside of your repo. (Or be willing to recreate it later.)
  2. Delete the file manually and commit it.
  3. Have your .gitignore updated to ignore that file if you haven't done this already. If you haven't committed the .gitignore change yet, consider including it in the previous commit so it's more obvious why it's getting deleted.
  4. Put the file back (or recreate it.)

The end result should be the same as if git rm --cached <file> did what you expected it to (and you commit that).

Note: regardless of whether you do it as I proposed, or with git rm --cached, for everyone else, when they get your changes, the file will be deleted. You will need to instruct them how to get it back, if they wish to do so.

TTT
  • 22,611
  • 8
  • 63
  • 69