Several months ago, we migrated a bunch of Subversion repositories to Git using svn-all-fast-export. (That information explains how this directory got in the Git directory in the first place, but probably isn't pertinent to removing it.) Today, one of our developers attempted to git checkout
an old branch of one of those repositories, only to be confronted with an error:
$ git checkout 2.3.4
error: invalid path 'MPC/.git/HEAD'
error: invalid path 'MPC/.git/config'
error: invalid path 'MPC/.git/description'
error: invalid path 'MPC/.git/hooks/applypatch-msg.sample'
...
error: invalid path 'MPC/.git/packed-refs'
error: invalid path 'MPC/.git/shallow'
$
A quick bit of sleuthing in our archived Subversion repository revealed that someone had committed a .git
directory (surely by mistake) to the MPC
directory years ago. They deleted it in the next branch. When the repository and its branches and commit history were migrated, that .git
directory got written to the Git tree, essentially "breaking" this branch. No big deal, right? Just delete the directory! Well ... how?
I can't check out the branch, so I can't simply git rm
. I tried git clone --single-branch --branch 2.3.4
but, no surprise here, I got the same error. Exactly what I was expecting. So I cloned with git --sparse
, but to my surprise, that still didn't work. The default sparse patterns:
/*
!/*/
Should mean that only the top-level files get checked out, but not anything under MPC
. However, when I try to check out the branch, I still get the same errors about that .git
directory, and the top-level of the working copy is completely empty. I've tried adding specific excludes such as !.git
, !\.git
, !.git/
, !\.git/
!MCP
, !/MPC
, !/MPC/.git
, !/MPC/\.git
, !/MPC/.git/
, !/MPC/\.git/
!/*/.git
, !/*/\.git
, !/*/.git/
, and !/*/\.git/
, and even more than that, but every pattern I try just gives me this error:
warning: unrecognized pattern: [the pattern I tried]
warning: disabling cone pattern matching
error: invalid path 'MPC/.git/HEAD'
...
Or:
warning: unrecognized negative pattern: [the pattern I tried]
warning: disabling cone pattern matching
error: invalid path 'MPC/.git/HEAD'
...
I do wonder if some combination of git mktree
, git write-tree
, and/or git commit-tree
can help me here, but I don't even know where to start with those commands.
To be clear ... if this becomes a show-stopper issue for my team and I can't find an easier solution, I will archive all new commits to this repo, re-migrate it, and re-apply all new commits. But I don't want to do that if I don't absolutely have to. That's days of time down the drain. There's gotta be a way to delete this ... right?