如何删除 git 中的本地存储库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1514054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I delete a local repository in git?
提问by Victor
I can't find the command. I tried Googling "git 'delete a repository'".
我找不到命令。我试过谷歌搜索“git'delete a repository'”。
回答by
Delete the .git
directory in the root-directory of your repository if you only want to delete the git-related information (branches, versions).
删除.git
目录版本库的根目录下,如果你只是想删除git的相关信息(分支,版本)。
If you want to delete everything (git-data, code, etc), just delete the whole directory.
如果要删除所有内容(git-data、代码等),只需删除整个目录即可。
.git directories are hidden by default, so you'll need to be able to view hidden files to delete it.
.git 目录默认是隐藏的,因此您需要能够查看隐藏文件才能将其删除。
回答by Azat
To piggyback on rkj's answer, to avoid endless prompts (and force the command recursively), enter the following into the command line, within the project folder:
要搭载rkj 的答案,以避免无休止的提示(并强制递归执行命令),请在项目文件夹内的命令行中输入以下内容:
$ rm -rf .git
Or to delete .gitignore and .gitmodules if any (via @aragaer):
或者删除 .gitignore 和 .gitmodules 如果有的话(通过@aragaer):
$ rm -rf .git*
Then from the same ex-repository folder, to see if hidden folder .git is still there:
然后从同一个 ex-repository 文件夹中,查看隐藏文件夹 .git 是否仍然存在:
$ ls -lah
If it's not, then congratulations, you've deleted your local git repo, but not a remote one if you had it. You can delete GitHub repo on their site (github.com).
如果不是,那么恭喜您,您已经删除了本地 git 存储库,但如果您拥有它,则不会删除远程存储库。您可以在他们的网站 (github.com) 上删除 GitHub 存储库。
To view hidden folders in Finder (Mac OS X) execute these two commands in your terminal window:
要在 Finder (Mac OS X) 中查看隐藏文件夹,请在终端窗口中执行以下两个命令:
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder
Source: http://lifehacker.com/188892/show-hidden-files-in-finder.
来源:http: //lifehacker.com/188892/show-hidden-files-in-finder。
回答by rkj
In the repository directory you remove the directory named .gitand that's all :). On Un*x it is hidden, so you might not see it from file browser, but
在存储库目录中,您删除名为.git 的目录,仅此而已:)。在 Un*x 上它是隐藏的,因此您可能无法从文件浏览器中看到它,但是
cd repository-path/
rm -r .git
should do the trick.
应该做的伎俩。
回答by LucianNovo
That's right, if you're on a mac(unix) you won't see .git in finder(the file browser). You can follow the directions above to delete and there are git commands that allow you to delete files as well(they are sometimes difficult to work with and learn, for example: on making a 'git rm -r ' command you might be prompted with a .git/ not found. Here is the git command specs:
没错,如果您使用的是 mac(unix),您将不会在 finder(文件浏览器)中看到 .git。您可以按照上面的说明进行删除,还有一些 git 命令也允许您删除文件(它们有时难以使用和学习,例如:在制作“git rm -r”命令时,您可能会收到提示没有找到 .git/。这是 git 命令规范:
usage: git rm [options] [--] ...
用法:git rm [选项] [--] ...
-n, --dry-run dry run
-q, --quiet do not list removed files
--cached only remove from the index
-f, --force override the up-to-date check
-r allow recursive removal
--ignore-unmatch exit with a zero status even if nothing matched
When I had to do this, deleting the objects and refs didn't matter. After I deleted the other files in the .git, I initialized a git repo with 'git init' and it created an empty repo.
当我不得不这样做时,删除对象和引用并不重要。删除 .git 中的其他文件后,我用“git init”初始化了一个 git 仓库,它创建了一个空仓库。