简体   繁体   English

删除Git存储库,但保留所有文件

[英]Remove Git repository, but keep all files

At some point during my adventures with Linux, I decided that it would be a good idea to put everything in my home directory into source control. 在我使用Linux进行冒险的某些时候,我决定将我的主目录中的所有内容放入源代码控制中是个好主意。 I'm not asking whether that was a good idea or not -- I'm asking how to undo it. 我不是在问这是不是一个好主意 - 我在问如何撤消它。

The reason for removing the repository is that I recently installed Oh My Zsh, and I really like it. 删除存储库的原因是我最近安装了Oh My Zsh,我真的很喜欢它。 The rub is that my home directory has a big git:(master) stuck behind it, and I'm just not a huge fan of that. 问题是我的主目录有一个很大的git:(master)卡在它后面,我只是不是那个的忠实粉丝。

在此输入图像描述

So what I would like to do is remove the git repository itself, so that the git:(master) is no longer displayed, without deleting all of my files. 所以我想要做的是删除git存储库本身,以便不再显示git:(master)而不删除我的所有文件。

Just remove (or rename) the .git subdirectory. 只需删除(或重命名) .git子目录即可。 That subdirectory is the whole of the repository. 该子目录是整个存储库。 This will not delete your files, but it will delete their history. 这不会删除您的文件,但删除其历史记录。

Additionally, there might be files like .gitignore and .gitattributes that are not necessary anymore. 此外,可能还有.gitignore.gitattributes等文件不再需要。

Make sure that all your files are present in the working tree before removing/renaming .git . 在删除/重命名.git之前,请确保所有文件都存在于工作树中。

Your repository resides in the .git directory, you can delete it easily. 您的存储库位于.git目录中,您可以轻松删除它。 But if only the prompt disturbs you, it is enough to search where PROMPT gets new value in your environment and modify it to something else. 但是,如果只有提示会扰乱您,那么搜索PROMPT在您的环境中获得新值并将其修改为其他内容就足够了。

Removing the directory .git in a repository removes the history , and keeps the files currently checked out - it does not keep all files . 删除存储库中的目录.git会删除历史记录 ,并保留当前检出的文件 - 它不会保留所有文件

Warning: this may not be what you need! 警告:这可能不是您所需要的!

The history contains earlier states of files, files that were removed at some time, and other branches , containing similar, up to date files similar to the currently checked out, or completely different ones. 历史记录包含文件的早期状态 ,在某些时间删除的文件以及其他分支 ,包含与当前检出的类似的最新文件,或完全不同的文件。

That means, in the general case, removing the .git affects files that where in the repository tree earlier, and files that currently - in the newest version - exist in other branches. 这意味着,在一般情况下,删除.git会影响先前存储库树中的文件以及当前(最新版本)存在于其他分支中的文件。 All these would be deleted too! 所有这些都将被删除!

The answers proposing to just delete .git apply only in the simplest case, 建议只删除.git的答案仅适用于最简单的情况,
where you only added files to the master branch since creating the repository, and master is checked out. 自创建存储库以来,您只将文件添加到主分支,并检出主服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM