git 如何完全删除用init创建的git存储库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1213430/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 06:48:51  来源:igfitidea点击:

How to fully delete a git repository created with init?

gitgit-init

提问by Thomas

I created a git repository with git init. I'd like to delete it entirely and init a new one.

我创建了一个 git 存储库git init。我想完全删除它并初始化一个新的。

回答by Kristof Provost

Git keeps all of its files in the .gitdirectory. Just remove that one and init again.

Git 将其所有文件保存在该.git目录中。只需删除那个并再次初始化。

If you can't find it, it's because it is hidden.

如果你找不到它,那是因为它被隐藏了。

  • In Windows 7, you need to go to your folder, click on Organizeon the top left, then click on Folder and search options, then click on the Viewtab and click on the Show hidden files, folders and drivesradio button.

  • On a Mac OS:

    • Open a Terminal (via Spotlight: press CMD+ SPACE, type terminaland press Enter) and run:

      defaults write com.apple.finder AppleShowAllFiles 1 && killall Finder
      

      Note: The keyboard shortcut to show hidden files in Finder is CMD+ SHIFT+ .so it is no longer necessary to modify the finder config this way

    • You could also type cd(the space is important), drag and drop your git repo folder from Finder to the terminal window, press return, then type rm -fr .git, then returnagain.

  • On Ubuntu, use shortcut Ctrl + H.

  • 在 Windows 7 中,您需要转到您的文件夹,单击Organize左上角的 ,然后单击Folder and search options,然后单击View选项卡并单击Show hidden files, folders and drives单选按钮。

  • 在 Mac 操作系统上:

    • 打开终端(通过 Spotlight:按CMD+ SPACE,输入terminal并按Enter)并运行:

      defaults write com.apple.finder AppleShowAllFiles 1 && killall Finder
      

      注:键盘快捷键在Finder中显示隐藏文件,则是 CMD+ SHIFT+ .,因此不再需要修改配置取景这种方式

    • 您也可以键入cd(空格很重要),将您的 git repo 文件夹从 Finder 拖放到终端窗口,按return,然后键入rm -fr .git,然后return再次键入。

  • 在 Ubuntu 上,使用快捷方式Ctrl + H

回答by CB Bailey

If you really want to remove all of the repository, leaving only the working directory then it should be as simple as this.

如果您真的想删除所有存储库,只保留工作目录,那么它应该像这样简单。

rm -rf .git

The usual provisos about rm -rfapply. Make sure you have an up to date backup and are absolutely sure that you're in the right place before running the command. etc., etc.

关于rm -rfapply的通常条件。确保您有最新的备份,并且在运行命令之前绝对确保您位于正确的位置。等等等等。

回答by ejazz

If you want to delete all .git folders in a project use the following command:

如果要删除项目中的所有 .git 文件夹,请使用以下命令:

find . -type f | grep -i "\.git" | xargs rm

This will also delete all the .git folders and .gitignore files from all subfolders

这也将删除所有子文件夹中的所有 .git 文件夹和 .gitignore 文件

回答by eckes

Alternative to killing TortoiseGit:

杀死 TortoiseGit 的替代方法:

  • Open the TortoiseGit-Settings (right click to any folder, TortoiseGit → Settings)
  • Go to the Icon Overlaysoption.
  • Change the Status Cachefrom Defaultto None
  • Now you can delete the directory (either with Windows Explorer or rmdir /S /Q)
  • Set back the Status Cachefrom Noneto Defaultand you should be fine again...
  • 打开 TortoiseGit-Settings(右键单击任意文件夹,TortoiseGit → Settings)
  • 转到图标叠加选项。
  • 状态缓存默认更改为
  • 现在您可以删除目录(使用 Windows 资源管理器或rmdir /S /Q
  • 折戟状态缓存默认,你应该再罚款...

回答by Scorpius

Where $GIT_DIR is the path to the folder to be searched (the git repo path), execute the following in terminal.

其中 $GIT_DIR 是要搜索的文件夹的路径(git repo 路径),在终端中执行以下命令。

find $GIT_DIR -name *.git* -ok rm -Rf {} \;

This will recursively search for any directories or files containing ".git" in the file/directory name within the specified Git directory. This will include .git/ and .gitignore files and any other .git-like assets. The command is interactive and will ask before removing. To proceed with the deletion, simply enter y, then Enter.

这将递归搜索指定 Git 目录中文件/目录名称中包含“.git”的任何目录或文件。这将包括 .git/ 和 .gitignore 文件以及任何其他类似 .git 的资产。该命令是交互式的,在删除之前会询问。要继续删除,只需输入 y,然后输入。

回答by Leonuch

after cloning the repo

克隆回购后

cd /repo folder/

to go to the file directory then

然后转到文件目录

ls -a

to see all files hidden and unhidden

查看所有隐藏和未隐藏的文件

.git .. .gitignore .etc

if you like you can check the repo origin

如果你愿意,你可以检查回购来源

git remote -v

now delete .git which contains everything about git

现在删除包含有关 git 的所有内容的 .git

rm -rf .git

after deleting, you would discover that there is no git linked check remote again

删除后,你会发现再次没有git链接检查远程

git remote -v

now you can initial your with

现在你可以用

git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/Leonuch/flex.git
git push -u origin master

回答by squal

To fully delete the .gitrepository in your computer (in Windows 8 and above):

要完全删除.git计算机中的存储库(在 Windows 8 及更高版本中):

  1. The .gitrepository is normally hidden in windows
  2. So you need to mark the "hidden items" to show the hidden folders
  3. At the top site of you directory you find "view" option
  4. Inside "view" option you find "hidden items" and mark it
  5. Then you see the .gitrepository then you can delete it
  1. .git库通常隐藏在视窗
  2. 所以你需要标记“隐藏项目”以显示隐藏文件夹
  3. 在您目录的顶部站点,您可以找到“查看”选项
  4. 在“查看”选项中,您可以找到“隐藏的项目”并标记它
  5. 然后你看到.git存储库然后你可以删除它

回答by Ahmad Awais

You can create an aliasfor it. I am using ZSH shell with Oh-my-Zsh and here is an handy alias:

您可以为其创建别名。我将 ZSH shell 与 Oh-my-Zsh 一起使用,这是一个方便的别名:

# delete and re-init git
# usage: just type 'gdelinit' in a local repository
alias gdelinit="trash .git && git init"

I am using Trashto trash the .gitfolder since using rmis really dangerous:

我正在使用垃圾箱来垃圾.git文件夹,因为使用rm真的很危险:

trash .git

Then I am re-initializing the git repo:

然后我重新初始化 git repo:

git init

回答by Deepak Keynes

No worries, Agreed with the above answers:

不用担心,同意楼上的回答:

But for Private project, please follow the steps for Gitlab:

但是对于私有项目,请按照 Gitlab 的步骤操作:

  1. Login to your account
  2. Click on Settings -> General
  3. Select your Repository (that you wants to delete)
  4. Click on 'Advanced' on the bottom-most
  5. Click on 'Remove Project'
  6. You will be asked to type your project name

    This action can lead to data loss. To prevent accidental actions we ask you to confirm your intention. Please type 'sample_project' to proceed or close this modal to cancel.

  7. Now your project is deleted successfully.

  1. 登录到您的帐户
  2. 点击设置->通用
  3. 选择您的存储库(您要删除的)
  4. 单击最底部的“高级”
  5. 点击“删除项目”
  6. 您将被要求输入您的项目名称

    此操作可能会导致数据丢失。为防止意外行为,我们要求您确认您的意图。请输入“sample_project”以继续或关闭此模式以取消。

  7. 现在您的项目已成功删除。

回答by sahil khurana

In windows:

在窗口中:

  1. Press Start Button
  2. Search Resource Monitor
  3. Under CPU Tab -> type .git -> right click rundll32 and end process
  1. 按开始按钮
  2. 搜索资源监视器
  3. 在 CPU 选项卡下 -> 键入 .git -> 右键单击​​ rundll32 并结束进程

Now you can delete .git folder

现在您可以删除 .git 文件夹