admin管理员组

文章数量:1314442

So I did "git init" in the wrong folder and now want to undo it (I want to do it in a subfolder of the current folder). Like I want to delet the hidden .git folder.

I already searched for some solution like "rm -rf .git" or "rmdir .git" but this does not work. (even in the administrator PowerShell)

When I do "rmdir .git" there is an error "Permission Denied". I also tried it in administrator powershell but i get the same error.

.git\hooks cannot
be removed: You do not have sufficient access rights to perform this operation.
In line:1 Character:1
+ rmdir .git
+ ~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (hooks:DirectoryInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
rmdir : The element C:\Users\...\.git\info cannot be
be removed: You do not have sufficient access permissions to perform this operation.
In line:1 Character:1

It is also strange that when i enter "git status" it shows that it is not a git repository? But when I list the hidden folder "ls -Hidden" then there is a folder named .git??

git status
fatal: not a git repository (or any of the parent directories): .git

ls -Hidden
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
darh-l        30.01.2025     10:25                .git

cd .git
ls
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
dar--l        30.01.2025     10:25                hooks
dar--l        30.01.2025     10:25                info
dar--l        30.01.2025     10:23                objects
dar--l        30.01.2025     10:23                refs

Thanks in advance.

So I did "git init" in the wrong folder and now want to undo it (I want to do it in a subfolder of the current folder). Like I want to delet the hidden .git folder.

I already searched for some solution like "rm -rf .git" or "rmdir .git" but this does not work. (even in the administrator PowerShell)

When I do "rmdir .git" there is an error "Permission Denied". I also tried it in administrator powershell but i get the same error.

.git\hooks cannot
be removed: You do not have sufficient access rights to perform this operation.
In line:1 Character:1
+ rmdir .git
+ ~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (hooks:DirectoryInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
rmdir : The element C:\Users\...\.git\info cannot be
be removed: You do not have sufficient access permissions to perform this operation.
In line:1 Character:1

It is also strange that when i enter "git status" it shows that it is not a git repository? But when I list the hidden folder "ls -Hidden" then there is a folder named .git??

git status
fatal: not a git repository (or any of the parent directories): .git

ls -Hidden
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
darh-l        30.01.2025     10:25                .git

cd .git
ls
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
dar--l        30.01.2025     10:25                hooks
dar--l        30.01.2025     10:25                info
dar--l        30.01.2025     10:23                objects
dar--l        30.01.2025     10:23                refs

Thanks in advance.

Share Improve this question asked Jan 30 at 11:29 PluscheinPluschein 12 bronze badges 2
  • just cut paste .git folder – TheGameiswar Commented Jan 30 at 11:32
  • 2 Thanks, i was able to show the hidden folder in the editor and then delete it;) – Pluschein Commented Jan 30 at 12:12
Add a comment  | 

1 Answer 1

Reset to default 0

I already searched for some solution like "rm -rf .git" or "rmdir .git" but this does not work. (even in the administrator PowerShell)

Likely not a permission-related problem then (as the repository files don't normally have any special permissions anyway). Might be that some program is holding a handle to the directory (your IDE, antivirus programs, third-party Explorer extensions, etc). Reboot to see if the problem goes away. If not, try running a chkdsk /f scan.

It is also strange that when i enter "git status" it shows that it is not a git repository? But when I list the hidden folder "ls -Hidden" then there is a folder named .git??

It is missing half the contents that would identify it as a Git repository (because you deleted those). For example, it no longer has .git\HEAD or .git\config.

本文标签: powershellDelete git in WindowsStack Overflow