blog/source/_posts/dot-git-folder-too-big-solu...

26 lines
976 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: 解决.git文件夹过大的问题
date: 2021-09-14 00:00:00
tags:
- git
- 技术
- 脚本
category: 技术
---
# 起因
事件起因是在之前的项目中,使用命令`git add .`将当前改动添加到暂存区。但是因为疏忽,刚刚放进来的几百兆大小的视频文件没有设置忽略,于是理所当然的被加入了暂存区...
然后,项目内的.git文件夹就一下子大了几百兆。我赶紧从暂存区取消掉视频文件但是.git文件夹并没有因此变小。继续执行`git commit`,即使版本管理中已经没有这个文件,.git文件夹依旧保持几百兆的大小。
# 解决方案
我认为这种情况肯定有解决方案,可以释放掉存在暂存区但实际上并没有被提交的无用文件。通过一番搜索和走了一点弯路后,发现只需要一条命令即可解决:
```shell
git gc --prune=now
```
执行命令后,文件夹大小立刻减小,问题解决。