Git: Remove directory with quotes and backslashes from repo

1.4k Views Asked by At

I have a directory in my git repository (but not on my local system) named

"my\\directory-name"

It contains two quotation marks and two backslashes.

The problem is that with this directory in my repo it is not possible to checkout the contents completely because (error message:) git doesn't find a directory named

my\directory-name

(I still can checkout every other directory and file separately..)

I already tried to escape the characters..

git rm -r '"my\\directory-name"'

git rm -r \"my\\\\directory-name\"

but git doesn't find any file matching. With git ls-tree HEAD I can see the directory in the repo.

Can anyone tell me how to remove such a directory from the git repo?

3

There are 3 best solutions below

0
On BEST ANSWER

I wasn't able to try this out, because my problem somehow solved itself. I checked out the files and directories from the repo one by one on another Windows system, except the "broken" directory. Then, when I commited the next time from my new working copy, the directory was in delete mode, so I simply could push and the directory was removed on the repository.

0
On

It sounds like the addition of the directory came from a Linux host or more precisely a host that did not have a problem creating a directory of the given name. Now you are experiencing problems checking out the state of the branch on windows, since the directory can not be created.

If that is the case, you should see a difference between the committed state of the git repository and the checkout with

git status

If this is the case, then you could work around the issue and remove the file like this:

  • check out the repository on a linux box
  • remove the directory in the linux checkout with

    git rm -r '"the\\dir"'

    git commit

    (quoting the name with single ticks like '"the\directory"' works for me)

  • push the changes to the git server from the linux ceckout
  • fetch and update the checkout on the windows box
0
On

I'm also having trouble with this

git status

produces

Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

deleted:    "\342\200\231"

I tried just about every combination I could think of:

git rm --cached -r "\342\200\231"
fatal: pathspec '\342\200\231' did not match any files
git rm --cached -r \342\200\231
fatal: pathspec '342200231' did not match any files
git rm --cached -r \\342\\200\\231
fatal: pathspec '\342\200\231' did not match any files
git rm --cached -r "\\342\\200\\231"
fatal: pathspec '\342\200\231' did not match any files
git rm --cached -r '"\\342\\200\\231"'
fatal: pathspec '"\\342\\200\\231"' did not match any files
git rm --cached -r '"\342\200\231"'
fatal: pathspec '"\342\200\231"' did not match any files
git rm --cached -r '\342\200\231'
fatal: pathspec '\342\200\231' did not match any files
git rm --cached -r '\\342\\200\\231'
fatal: pathspec '\\342\\200\\231' did not match any files

git version 2.7.4 on Ubunut