Home  >  Article  >  Development Tools  >  How to delete the .git directory

How to delete the .git directory

WBOY
WBOYOriginal
2022-06-30 16:37:055362browse

In git, you can call the command line in the directory of the local warehouse to delete the ".git" folder in the root directory. The syntax is "find . -name ".git" | xargs rm -Rf"; After clearing the local warehouse, you can use the "rm -rf github warehouse address" command to delete the library in the setting of the corresponding library in github.

How to delete the .git directory

The operating environment of this article: Windows 10 system, Git version 2.30.0, Dell G3 computer.

How to delete the .git directory

1. Delete the .git folder

  1. Invoke the command line in the directory of the local warehouse to delete the root In the .git folder under the directory, enter
find . -name ".git" | xargs rm -Rf
# OR
rm -rf .git

so that the local warehouse is cleared. As shown below, the master is gone.
How to delete the .git directory
2. Manually delete the remaining .git files

  1. Enter rm -rf github warehouse address in the command line, for example

rm -rf https://github.com/xxx/xxx.git

  1. Go to the setting in the corresponding library of github and delete it library.

Extended knowledge:

.gitThe file is too large! Delete large files

When we use Git on a daily basis, for smaller projects, we may not notice the .git file.

In fact, the .git file is mainly used to record the changes submitted each time. When our project gets bigger and bigger, we find that the .git file is getting bigger and bigger.

It is very likely that a large file was submitted. If you submitted a large file, even if you delete it in a later version,

In fact, the Large files are still there.

why? Think about it carefully, although you deleted the large files in later versions, Git has a version regression function, so if the large files are not recorded, what will

git do to roll back the files for you? ? However, the problem caused by the increasing size of .git files is that it takes a lot of time to pull the project every time, and everyone spends

so much time. .

git gives a solution, use git branch-filter to traverse git history tree, you can permanently delete large files in the history, so that the .git file can be The purpose of losing weight.

The steps are given below (the following steps are very dangerous, please operate with caution! Don’t delete the company haha)

First find out the top five files in git:
git verify-pack -v .git/objects/pack/pack-*.idx | sort -k 3 -g | tail -5
The execution result actually looks like this:
How to delete the .git directory
The letters in the first line are actually equivalent to the file id. Use the following command to find out the file name corresponding to the id:
git rev-list --objects --all | grep 8f10eff91bb6aa2de1f5d096ee2e1687b0eab007
Ok, the largest file is found. How to delete it?

git filter-branch --index-filter 'git rm --cached --ignore-unmatch <your-file-name>'
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git fsck --full --unreachable
git repack -A -d
git gc --aggressive --prune=now
git push --force [remote] master</your-file-name>

First of all, the two most important commands are git filter-branch and gc. Filter-branch is really cleaning, but just running it is useless. Yes, you need to delete the backup files, repackage, etc. The final gc command is used to collect the generated garbage and finally clear the large files.

Recommended study: "Git Tutorial"

The above is the detailed content of How to delete the .git directory. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn