简体   繁体   中英

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. 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. 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.

在此输入图像描述

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.

Just remove (or rename) the .git subdirectory. 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.

Make sure that all your files are present in the working tree before removing/renaming .git .

Your repository resides in the .git directory, you can delete it easily. 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.

Removing the directory .git in a repository removes the history , and keeps the files currently checked out - it does not keep all files .

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. All these would be deleted too!

The answers proposing to just delete .git apply only in the simplest case,
where you only added files to the master branch since creating the repository, and master is checked out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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