Home > Mobile >  git deletion of a directory failed during checkout another branch, the directory name has a plus &qu
git deletion of a directory failed during checkout another branch, the directory name has a plus &qu

Time:01-05

Description: I have a git repo with multiple branches, code is MATLAB files. While I'm trying to switch from branch A to another branch B after adding codes in A by typing git checkout B, I get this message in Git Bash: Deletion of directory ' pkgFldr' failed. Should I try again (y/n). I chose "y", it failed again and same message persists. I chose "n", then the branch switch was only half-way done, as most of the files weren't switched to branch B.

Thinking: The folder pkgFldr has a plus sign at the beginning because this is how MATLAB marks a package folder. Could this plus sign be the reason why the branch switch wasn't successful? How can I resolve this, thanks.

CodePudding user response:

It sounds like you're on Windows, and Windows has the behavior where by default, files that are in use cannot be deleted or replaced with new files. That may have seemed like a good idea at the time, but we now know that was a mistake.

You'll need to figure out what program has the file open, and cause it to close the file, or quit the program, before this will work. This will be true regardless of the name of the file or directory, and is just a limitation of Windows.

You may wish to work with your files entirely under WSL, which doesn't have this issue, or on a Linux or Mac system, which don't, either.

CodePudding user response:

MATLAB (for Windows at least) sometimes locks files which are on its path, as if they were being held open. Because you're using a package folder (the " " prefix) this can be especially true.

Either remove the parent folder from your current path (since package folders are automatically on the path when their parent is), or simply close MATLAB. Then retry your Git operation.

  •  Tags:  
  • Related